I am trying global context. But showed error. How to fix?
My code.
final _appRouter = AppRouter(); ///Used auto_route
MaterialApp.router(
routerConfig: _appRouter.config(navigatorObservers: () => [HeroController()]),
scaffoldMessengerKey: scaffoldMessengerKey,
builder: (context, child) {
globalContext = context;
return builder == null`enter code here`
? (child ?? const Material())
: builder!(context, child ?? const Material());
});
///--Used globalContext
showDialog(
context: globalContext!,
builder: (BuildContext context) {
return DialogDesignSimple(
child: child, title: title, maxWidth: maxWidth);
});
///---Used scaffoldMessengerKey
showDialog(
context: scaffoldMessengerKey!.currentContext,
builder: (BuildContext context) {
return DialogDesignSimple(
child: child, title: title, maxWidth: maxWidth);
});
Error output
Another exception was thrown: Navigator operation requested with a context that does not include a Navigator.