skip to Main Content

I’m creating series of modal bottom sheet in my app. When I go to A modal bottom sheet to B modal bottom sheet then A modal bottom sheet should be closed, I’m not getting how to achieve this, when I use navigator.pop, then it’s navigating to A bottom sheet.

2

Answers


  1. Before you go to B bottom sheet, you should call Navigator.pop

    Example:

    InkWell(
                onTap: () {
                  showModalBottomSheet(
                      context: context,
                      builder: (context) {
                        return InkWell(
                            onTap: () {
                              Navigator.of(context).pop();
                              showModalBottomSheet(
                                  context: context,
                                  builder: (context) {
                                    return const Text("Bottom Sheet B");
                                  });
                            },
                            child: const Text("Bottom Sheet A"));
                      });
                },
                child: const Text("Home"),
              ),
    
    Login or Signup to reply.
  2. You can simply return the status from sheet A while closing. Based on that open sheet B.

    Example:

    InkWell(
                          child: Text('Press me'),
                          onTap: () async {
                            final result = await showModalBottomSheet(
                              context: context,
                              builder: (context) => InkWell(
                                child: Text('Open SHeet B'),
                                onTap: () => Navigator.pop(context, true),
                              ),
                            );
                            print(result);
                            if (mounted && result == true) {
                              showModalBottomSheet(
                                context: context,
                                builder: (context) => InkWell(
                                  child: Text('CLose SHeet B'),
                                  onTap: () => Navigator.pop(context, true),
                                ),
                              );
                            }
                          },
                        ),
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search