Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigator routes Clear the stack of flutter

Tags:

flutter

dart

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!

like image 804
sarvesh chavan Avatar asked Jun 27 '18 21:06

sarvesh chavan


People also ask

What is navigator Pushnamed in Flutter?

Push a named route onto the navigator that most tightly encloses the given context. The route name will be passed to the Navigator. onGenerateRoute callback. The returned route will be pushed into the navigator. The new route and the previous route (if any) are notified (see Route.


2 Answers

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

void _logout() {    Navigator.pushNamedAndRemoveUntil(context, "/newRouteName", (r) => false); } 
like image 61
Paul Iluhin Avatar answered Oct 06 '22 18:10

Paul Iluhin


Use Navigator.popUntil.

void _logout() {   Navigator.popUntil(context, ModalRoute.withName('/login')); } 
like image 45
Jacob Phillips Avatar answered Oct 06 '22 20:10

Jacob Phillips