SowingFiber
SowingFiber

Reputation: 1244

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.

Upvotes: 7

Views: 19719

Answers (2)

Luis Cardoza Bird
Luis Cardoza Bird

Reputation: 1472

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.

Upvotes: 1

Vinz
Vinz

Reputation: 240

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

Upvotes: 2

Related Questions