Flutter:- How to back or redirect(Navigation) 3-4 screen previous

Viewed 849

Suppose I have 6 screen "A", "B", "C", "D", "E", "F". First I have to navigate all the screens one by one(A=>B=C=>D=>E=>F). After that, I want to redirect the screen "F" to Screen "C" and it's working. Now my current screen is "C", So my issue is after using the back button or on back press my screen navigate to "E". but I want to navigate to screen "B".

Notes:- I don't want to use Get.off when navigating the "D"=>"E"="F".

I'm using the Get plugin for this.

2 Answers

You can use popuntil

  • Navigator.of(context).popUntil((route) => route.isFirst);
  • Navigator.of(context).pushNamedAndRemoveUntil('/screen4', ModalRoute.withName('/screen1'));

or

()=> Navigator.pushAndRemoveUntil(
                      context,
                      MaterialPageRoute(builder: (BuildContext context) => LoginPage()),
                      ModalRoute.withName('/'),
                    )

or just pop everything and then push replacement.

Navigator.of(context).pop();
// More pop
Navigator.pushReplacement(
      context, MaterialPageRoute(builder: (BuildContext context) => A()));
}

Try

Get.offUntil(pageB, (route) => route is pageA);
Related