Navigator routes Clear the stack of flutter

烈酒焚心 提交于 2021-02-06 14:20:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!