Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed assertion: !_debugLocked is not true when using Navigator.popUntil() in Flutter

In my flutter app I use this code to go to my dashboard page, but it fails to do so the first time and I get the debugLocked error.

The launch page in the app is a Router that checks for shared preferences "sessionid" which, if set, takes the user directly to the Dashboard, else takes them to the login.

Without the below code, I get to my Dashboard just fine, using Navigator.pushReplacement() but then, a back arrow appears on the appBar. This back button takes the app back to the Router.

I searched for answers on how to remove all screens from the navigator and the following was what I found.

Navigator.of(context).popUntil(ModalRoute.withName(Dashboard.id));

Using the above code gives me the debugLocked error. Is there a solution to mitigate this problem? Or is there any other efficient way for me to remove screens from the context? Does setting automaticallyImplyLeading to false help somehow? Because this error only occurs after someone has logged in or signed up.

like image 783
SowingFiber Avatar asked Nov 06 '22 13:11

SowingFiber


2 Answers

to remove all the previous routes use Navigator.pushAndRemoveUntil()

like image 188
Vinz Avatar answered Nov 15 '22 06:11

Vinz


This can be another alternative, if you for some reason face a setState error.

navigationService.popUntil((_) => true);
navigationService.navigateTo(
  'authentication',
);

basically i wait until the navigation finish setting everything and then call the navigateTo.

like image 20
Luis Cardoza Bird Avatar answered Nov 15 '22 07:11

Luis Cardoza Bird