final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider<InactivityCubit>(
create: (_) => inject<InactivityCubit>(),
child: MaterialApp.router(
builder: (context, widget) {
return Container(
child: BlocListener<InactivityCubit, InactivityState>(
listener: (context, state) => state.whenOrNull(
showDialog: () {
final currentContext = navigatorKey.currentContext!;
AmazingDialog.show(currentContext!);
return null;
},
),
child: widget,
),
);
},
theme: appTheme,
routerConfig: inject<GoRouter>(),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
),
);
}
}
How to open dialog above all screens in flutter, when using go_router? In my code I have an error because navigatorKey.currentContext is null.