I pushed four screens ScreenOne >> ScreenTwo >> ScreenThree >> ScreenFour
and I'm at ScreenFour now I want to pop back to ScreenTwo
In Swift it works like this::
if let viewControllers: [UIViewController] = self.navigationController!.viewControllers {
for vc in viewControllers
{
if (vc is SecondViewController)
{
self.navigationController!.popToViewController(vc, animated: true)
}
}
}
how i perform this operation in flutter.
Please give a solution, Thank you.
You can use the Navigator widget to provide any number of individual navigators in your app. Each Navigator will maintain it's own navigation stack. For example, if you wanted to split your app vertically with each half having it's own navigation stack: Column( children: <Widget>[ Navigator(...), Navigator(...) ] )
What is the WillPopScope widget? The WillPopScope widget comes with the Flutter framework. It gives us control over the back button action, allowing the current page to go back to the previous one if it meets certain requirements. This is achieved using a callback, which the widget takes in as one of its parameters.
If you didn't define any route in the MaterialApp then you need to define at the time of push.
Navigator.of(context).push(
MaterialPageRoute(builder: (_) {
return SecondPage();
},
settings: RouteSettings(name: 'SecondPage',),
));
You need to define the same route name
Navigator.of(context).popUntil((route){
return route.settings.name == 'SecondPage';
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With