问题
In my app i have three screens login , verifyotp , generatepass. I know how to move from one page to other page eg: Navigator.pushNamed(context, "/theNameOfThePage");
.
I have a flow in which i move from login->verifyotp->generatepass my question is now how can i move from generatepass to login page and clearing all the stack.
I am an android developer so in android we have intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
.
How can i achieve same result in flutter!
回答1:
Full clean of Navigator's history and navigate to new route:
void _logout() {
Navigator.pushNamedAndRemoveUntil(context, "/newRouteName", (r) => false);
}
回答2:
Use Navigator.popUntil.
void _logout() {
Navigator.popUntil(context, ModalRoute.withName('/login'));
}
来源:https://stackoverflow.com/questions/51071933/navigator-routes-clear-the-stack-of-flutter