[ERROR: '!navigator._debugLocked': is not true.] - flutter

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2845 pos 18: '!navigator._debugLocked': is not true.
That bug when run my app. I'm not fix. I try below code but not working
Future.delayed(Duration.zero, () {
Navigator.pushReplacement(context, PageTransition(
type: PageTransitionType.leftToRight,
child: HomeScreen(),
));
});

Stop your running app and reinstall the app to device
this is state issue

Related

Unhandled Exception: Null check operator used on a null value in flutter

I hope you are well, I will give you a bit of context about my problem...
I really don't know why this error happens and I've seen many similar publications but they haven't worked for me.
I'm new to flutter and I'm working on an app, but when the user wants to log out, the app crashes and shows the following error:
E/flutter (12659): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter (12659): #0 StatefulElement.state
package:flutter/…/widgets/framework.dart:4999
E/flutter (12659): #1 Navigator.of
package:flutter/…/widgets/navigator.dart:2543
E/flutter (12659): #2 Navigator.pushReplacement
package:flutter/…/widgets/navigator.dart:2105
E/flutter (12659): #3 MainCoordinator.logoutNavigation
package:domicilios/…/MainCoordinator/MainCoordinator.dart:62
E/flutter (12659): #4 UserActions.signOut.<anonymous closure>.<anonymous closure>
package:domicilios/…/View/ProfileTab.dart:222
E/flutter (12659): <asynchronous suspension>
This is the code that generates this error, I hope you can help me, thank you very much for your attention.
this is the class:
extension UserActions on _ProfileTabState {
void signOut(BuildContext context) {
AlertView.showAlertDialog(
model: AlertViewModel(
context,
const AssetImage('assets/logout.png'),
'Cierre de sesión en curso',
"¿Desear salir de la sesión actual?",
'Cerrar sesión',
"Cancelar", () {
_profileTabViewModel
.signOut()
.then((value) => coordinator.logoutNavigation(context: context));
}, () {
Navigator.pop(context);
}));
}
}
That's how I call it in the code:
onTap: () => signOut(context),
This is most likely due to the widget being unmounted before navigating.
You can check if the widget is mounted before navigating.
if (mounted) {
_profileTabViewModel.signOut().then((value) {
if (mounted) {
coordinator.logoutNavigation(context: context);
}
});
}
Also,
if(mounted){
Navigator.pop(context);
}

Error: _AssertionError ('package:flutter/src/widgets/navigator.dart': Failed assertion: line 4893 pos 12: '!_debugLocked': is not true.)

I am new in Flutter. I face a problem about _AssertionError ('package:flutter/src/widgets/navigator.dart': Failed assertion: line 4893 pos 12: '!_debugLocked': is not true.). I've been looking for a way to fix this for a long time, but I still can't find a solution.
I would be very grateful for any user help.
Just add this to your code:
Future.delayed(Duration.zero, () {
Navigator.pop(context);
});
Try the following code:
Future.delayed(const Duration(milliseconds: 10), () {
Navigator.of(context, rootNavigator: true).pop();
});

Can any one tell what is wrong with this Dialog?

I have this dialog But when I call it it gives me this error :
Unhandled Exception: 'package:flutter/src/widgets/localizations.dart': Failed assertion: line 453 pos 12: 'context != null': is not true.,
My Code:
return showDialog(
context: context,
child: AlertDialog(
title: Text(title),
content: Text(msg),
actions: [cancel, ok],
),
);
The error message tells you exactly what's wrong: your variable context is null.
You need to provide a context that is not null.
You should also provide builder instead of a child, because that way to build a dialog is deprecated for good reason.

Check if popUntil possible / Check if named route in navigation stack

How can I check if there is a route with name workout in my navigation stack? Whenever I call popUntil and the route is not in my stack, I get:
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Navigator-[GlobalObjectKey<NavigatorState> _WidgetsAppState#9d229](dirty, state: NavigatorState#86712(tickers: tracking 2 tickers)):
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2330 pos 12: '!_debugLocked': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
The relevant error-causing widget was
MaterialApp
lib/main.dart:58
When the exception was thrown, this was the stack
#2 NavigatorState.build
package:flutter/…/widgets/navigator.dart:2330
#3 StatefulElement.build
package:flutter/…/widgets/framework.dart:4334
I have tried this but popUntil still throws the exception
try {
Navigator.popUntil(context, ModalRoute.withName('workout'));
} catch (e) {
Future.delayed(Duration(milliseconds: 1000), () {
Navigator.push(context, MaterialPageRoute(
builder: (_context) => WorkoutPage(),
settings: RouteSettings(name: 'workout'),
fullscreenDialog: true
));
});
}
If you are working on clearing the entire stack and showing a specific screen, you should try the below code:
Navigator.of(context).pushNamedAndRemoveUntil('/screen4', (Route route) => false);
It should do the work.

Navigator.removeRoute & Navigator.removeRouteBelow

There are two functions in Navigator.dart, removeRoute and removeRouteBelow. I don't know how to use these two methods. This is the page route: / -> A -> B -> C -> D. And I perform this code in page D:
Navigator.removeRoute(context, MaterialPageRoute(builder: (context) => PushPageB()));
But there goes something wrong:
══╡ EXCEPTION CAUGHT BY GESTURE ╞═════════════════════════════════
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 1832 pos 12: 'route._navigator
== this': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new
When the exception was thrown, this was the stack:
2 NavigatorState.removeRoute (package:flutter/src/widgets/navigator.dart:1832:12)
3 Navigator.removeRoute (package:flutter/src/widgets/navigator.dart:1221:34)
4 PushPageE.build.<anonymous closure> (package:flutter_navigation/push_page_1.dart:223:29)
5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
6 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
8 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
9 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
12 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
13 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
14 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
16 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
18 _invoke1 (dart:ui/hooks.dart:153:13)
19 _dispatchPointerDataPacket (dart:ui/hooks.dart:107:5)
(elided 2 frames from class _AssertionError)
Handler: onTap
Recognizer:
TapGestureRecognizer#2a91c(debugOwner: GestureDetector, state: possible, won arena, finalPosition:
Offset(211.1, 411.1), sent tap down)
══════════════════════════════════════════════════════════════════
I don't know why would this happened, and how use these two methods correctly.
The MaterialPageRoute you have created inside Navigator.removeRoute call has no connection to the Navigator because it wasn't pushed yet. Therefore you've got an error.
In order to use removeRoute method correctly you need to remeber a route you pushed to the Navigator.
I am using following code to keep just one instance of a page in the Navigator.
var filterRoutes = <String, MaterialPageRoute<dynamic>>{'page1': null, 'page2': null, 'page3': null, 'page4': null};
MaterialPageRoute getNextRoute(BuildContext context, String nextPage) {
var route;
switch (nextPage) {
case 'page1':
route = MaterialPageRoute(builder: (context) => Page1());
break;
case 'page2':
route = MaterialPageRoute(builder: (context) => Page2());
break;
case 'page3':
route = MaterialPageRoute(builder: (context) => Page3());
break;
case 'page4':
route = MaterialPageRoute(builder: (context) => Page4());
break;
default:
route = MaterialPageRoute(builder: (context) => SomeOtherPage());
}
if (nextPage != null) {
if (filterRoutes[nextPage] != null) {
Navigator.removeRoute(context, filterRoutes[nextPage]);
}
filterRoutes[nextPage] = route;
}
return route;
}
If you want to remove blow router and go to new route like logout from setting and go to login page, you can do this:
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>
LoginScreen()), (Route<dynamic> route) => false);