I am trying to go to a page when notification is clicked. It works fine when app is in background or foreground but it is not working when app is killed.
When app is killed it opens the app but doesn’t go to the route defined in the notification data.
Need a quick solution
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message)=>
NotificationPop().onOpenApp(message, navigatorKey));
2
Answers
When you want to navigate or catch data from your notification(also known as RemoteMessage) when the app is killed, you need to use the following function of Firebase Package:
Place the above function in the init function of your desired page and whenever your app navigates to that page, the above function will get called.
I am assuming you have integrated the firebase in your app correctly.
Firebase package provides different methods to handle different scenarios, i.e. Terminated app, app in background and open app.
You have to implement
getInitialMessage()
method to handle notification in terminated app.You can also check other methods to manage diff scenarios like duplicate notifications: