dartflutter

Navigator routes Clear the stack of flutter


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!


Solution

  • Full clean of Navigator's history and navigate to new route:

    void _logout() {
       Navigator.pushNamedAndRemoveUntil(context, "/newRouteName", (r) => false);
    }