I am recursively adding routes to the navigator. There could be 20 views or more. Pop works as advertised, but I would like to pop to index 1 and remove all push history. is there a way to replace this pop command with something like... returntoIndex0...
new ListTile(
title: new RaisedButton(
child: new Text("POP"),
onPressed: () {
var route = new MaterialPageRoute(
builder: (BuildContext context) =>
new NextPage3(value:"hi there from 3"),
);
Navigator.pop(context);
},
),
),
To return data to the first screen, use the Navigator. pop() method, which accepts an optional second argument called result . Any result is returned to the Future in the SelectionButton.
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 do not use named routes, you can use
Navigator.of(context).popUntil((route) => route.isFirst);
In case you know exactly how many pops should be performed:
For example for 2 pops:
count = 0;
Navigator.popUntil(context, (route) {
return count++ == 2;
});
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