I want to know if there is a way to use a Global Context in a Flutter App while using auto route as MaterialApp.router() don't have a navigatorKey.
I want to know if there is a way to use a Global Context in a Flutter App while using auto route as MaterialApp.router() don't have a navigatorKey.
Specify scaffoldMessengerKey to MaterialApp:
final snackbarKey = GlobalKey<ScaffoldMessengerState>();
...
MaterialApp(
scaffoldMessengerKey: snackbarKey,
You can get the context from GlobalKey:
snackbarKey.currentState?.context