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

SowingFiber picture SowingFiber · Oct 18, 2019 · Viewed 7.5k times · Source

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.

Answer

Vinz picture Vinz · Oct 18, 2019

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