Error: Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2845 pos 18: '!navigator._debugLocked': is not true

Viewed 2593

I face a problem about Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2845 pos 18: '!navigator._debugLocked': is not true.

This is my Debug Console:

E/flutter ( 5236): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2845 pos 18: '!navigator._debugLocked': is not true.
package:flutter/…/widgets/navigator.dart:2845
E/flutter ( 5236): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter ( 5236): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter ( 5236): #2      _RouteEntry.handlePush.<anonymous closure>
package:flutter/…/widgets/navigator.dart:2845
E/flutter ( 5236): #3      TickerFuture.whenCompleteOrCancel.thunk
package:flutter/…/scheduler/ticker.dart:407
E/flutter ( 5236): #4      _rootRunUnary (dart:async/zone.dart:1434:47)
E/flutter ( 5236): #5      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter ( 5236): <asynchronous suspension>
E/flutter ( 5236): #6      TickerFuture.whenCompleteOrCancel.thunk
package:flutter/…/scheduler/ticker.dart:406
E/flutter ( 5236): <asynchronous suspension>
E/flutter ( 5236):

Here is some code:

Navigator.pop(context);

How can I fix this?

3 Answers

One of the way to solve this error is

Setting (Route<dynamic> route) => false will make sure that all routes before the pushed route are removed. This removes all routes in the stack so that user cannot go back to the previous routes after they have logged out.

if this does not work than you are on obsolete version of the framework. Current stable is 2.10.1. I recommend you to upgrade to latest which should resolve your issue.

  • Replace Navigator.pop(context) with Navigator.of(context).pop(context)

  • And Restart your application.

Related