When looking for on how to clear all routes and replace with a new one, all the solutions propose something like this
void clearStackAndReplace(String path, Object? extra) {
while (canPop() == true) {
pop();
}
pushReplacement(path, extra: extra);
}
But pushReplacement
is preseving the state of the new route, and I don’t want this, since I have some code on the initState
method of the new route that I want to run.
How can I do this?
2
Answers
You can write a function to pop every route, and push a new one when it’s empty, something likw this:
getGoRouter is an instance of GoRouter
What about
Navigator.popUntil(context, ModalRoute.withName('/login'));
?here the reference