'flutter pop back to navigated route
i am looking for proper solution to pop back to page where user was navigated. I already found this answer but i do believe there should be more proper way to do that. Any idea except the link that i shared?
Solution 1:[1]
You can pop until a certain page by doing Navigator.popUntil()
For example:
Navigator.of(context).popUntil((route) => route.settings.name == "MyWidget");
Just change "My Widget" to the name of the class you need to go back to and you'll be all good! Alternatively, you can try:
Navigator.of(context).popUntil((route) => route.isFirst);
Edit after @aligur's comment:
@aligur you could do the following, though it's not great form:
Setup a "globals" dart file, and put a variable in it. For example:
String pageToGoBackTo = "";
And whenever you know what page you want to set as the one to go back to, you set this variable to that page's route name. Then when you want to go back to it you can do:
Navigator.of(context).popUntil((route) => route.settings.name == pageToGoBackTo);
Hope this helps! :)
Good luck! :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |