Flutter/Dart - Navigator.pop(context) - How to Pop two Contexts back?

4.5k views Asked by At

I've got;

  • screen/widget Home() which calls;

  • screen/widget MainStage() which calls;

  • future method futureStage() which builds;

  • PageViewBuilder StageBuilder() which contains;

SwipeGestureRecognizer which calls;

Navigator.push (context,
                  PageTransition(
                    type: PageTransitionType.downToUp,
                    child: HomeReply(),
                  ));
  • HomeReply() contains;
  • appBar with an arrow/button that allows the user to;
  • Navigator.pop(context);

How do I get the Navigator to pop back to Home()?

2

There are 2 answers

0
Meggy On BEST ANSWER

Turns out HomeReply() had an extra MaterialApp in the build. Once I removed this it all worked as normal with Navigator.pop(context);.

5
Zeeshan Hussain On

The navigator is a stack so you can use the popUntil method to pop back to your home() screen.

Navigator.popUntil(context, ModalRoute.withName('/home'));

or

Navigator.of(context).popUntil((route) => route.settings.name == "Home");