skip to Main Content

I used the bottom sheet and I’m using navigator.pop on the button inside the bottom sheet but want to refresh the first screen when calling popup…

code

showModalBottomSheet(
    context: context,
    builder: (BuildContext bc) {
      return Container(
        child: Wrap(
          children: <Widget>[
          
          ListTile(
              leading: Icon(Icons.delete),
              title: Text('delete'),
              onTap: () async {
                

                try {
                  final file = await File(path);
                  print(path);
                  await file.delete();


                  print(file);
                } catch (e) {
                  print(e.toString());

                }
                Navigator.pop(context);
                setState(() {
                  print('delete');
                });

3

Answers


  1. class MyHomePage extends StatefulWidget {
      const MyHomePage({Key? key}) : super(key: key);
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      String homeScreenText = "Bottom Sheet not opened";
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(homeScreenText),
                const SizedBox(height: 50),
                ElevatedButton(
                  onPressed: () {
                    showBS();
                  },
                  child: const Text("open bottom sheet"),
                ),
              ],
            ),
          ),
        );
      }
    
      showBS() {
        showModalBottomSheet(
          context: context,
          builder: (context) {
            return SizedBox(
              height: 300,
              width: double.infinity,
              child: Center(
                child: ElevatedButton(
                    onPressed: () {
                    // Delete item from the list
                      // then call these
                      Navigator.pop(context);
                      setState(() {});
                    },
                    child: const Text("Close")),
              ),
            );
          },
        );
      }
    }
    
    Login or Signup to reply.
  2. You just need to pass class name beside the Navigator.

    Like this:-

    Navigator.pop(context,classname());
    
    Login or Signup to reply.
  3. This perfectly work’s for me and hoping that also work’s for you.`

    Note:- If you note get data then call that method many times.

    If You try to get data from any method then call that method after `

    Navigator.pop(context)
    method name();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search