Home > Mobile >  How to remove last two screen
How to remove last two screen

Time:11-12

I have some screen - (A-B-C-D-E-F) and from F screen I want to remove D-E-F screen and land to C Screen. So screen in stack : (A-B-C). Can you let me know how can I do this. I already try:

 Get.offUntil(MaterialPageRoute(builder: (context) => Second()),(Route<dynamic> route) => false);

and

Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>
                          Second()), (Route<dynamic> route) => false);
                    }),

But not working.

CodePudding user response:

try this

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

or you can simply pop 3 times like

Navigator.of(context)..pop()..pop()..pop();

CodePudding user response:

Do this on your third route

Navigator.pushReplacement(   context,   MaterialPageRoute(settings: RouteSettings(name: "Foo")), );

and at last screen you can call this.

Navigator.popUntil(context, ModalRoute.withName("Foo"));
  • Related