I have a fcm_service class (this service is not a widget) with my firebase configure method :
firebaseMessaging.configure(onLaunch: (Map<String, dynamic> msg) {
print("onLaunch called");
}, onResume: (Map<String, dynamic> msg) {
print("onResume called");
Navigator.of(context).pop();
}, onMessage: (Map<String, dynamic> msg) {
print("onMessage called : " + msg.toString());
Navigator.of(context).pop();
});
I want to be redirected on my main page in "onResume" but nothing happens. When I press on the notification, onResume is called (the print works).
What I've been trying :
Calling my page like : new MainPage();
Setting the context of my parent widget in my fcm_service class and use the Navigator like in the code above.
Is it even possible to be redirected through this class which is not a widget ?
EDIT :
Here is my main class :
class PreesmApp extends StatefulWidget {
@override
_PreesmAppState createState() => _PreesmAppState();
}
class _PreesmAppState extends State<PreesmApp>{
AuthenticationBloc _authenticationBloc;
final FCMService fcmService = Injector.getInjector().get<FCMService>();
@override
void initState() {
_authenticationBloc = AuthenticationBloc();
_authenticationBloc.dispatch(AppStarted());
super.initState();
fcmService.setContext(context);
}
@override
void dispose() {
_authenticationBloc.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlocProvider<AuthenticationBloc>(
bloc: _authenticationBloc,
child: MaterialApp(
supportedLocales: [
const Locale('en', 'EN'),
const Locale('fr', 'BE')
],
localizationsDelegates: [
const DemoLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
localeResolutionCallback:
(Locale locale, Iterable<Locale> supportedLocales) {
for (Locale supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode ||
supportedLocale.countryCode == locale.countryCode) {
return supportedLocale;
}
}
return supportedLocales.first;
},
debugShowCheckedModeBanner: false,
home: BlocBuilder<AuthenticationEvent, AuthenticationState>(
bloc: _authenticationBloc,
builder: (BuildContext context, AuthenticationState state) {
if (state is AuthenticationUninitialized) {
return SplashScreen();
}
if (state is AuthenticationAuthenticated) {
return DashboardPage();
}
if (state is AuthenticationUnauthenticated) {
return AuthenticationPage();
}
if (state is AuthenticationLoading) {
return LoadingIndicator();
}
},
),
routes: {
'/login': (context) => AuthenticationPage(),
'/dashboard': (context) => DashboardPage(),
'menu': (context) => MenuPage(),
'/kanbanBoard': (context) => KanbanBoardPage(),
'/listBoard': (context) => ListBoardPage(),
'/ganttBoard': (context) => GanttBoardPage(),
'/preesm': (context) => PreesmApp(),
},
theme: ThemeSwitcher.of(context).themeData,
));
}
}
And this is my context setter in fcm_service
setContext(BuildContext c) {
this.context = c;
}