Reputation: 1
I am using Flutter's awesome notification library to create and receive push notifications in an Android application. The notification is received in all states, i.e. foreground, background and killed state. And notification click is also working fine and navigating to desired screen in foreground and background states. But click is not working in killed state. It is just opening the app but not navigating to desired screen.
For handling the notification click and navigation route in killed state, I am using the following code:
Future<void> setupFirebaseMessaging() async {
// this code is working fine for iOS app in killed state but for android app remoteMessage is always return null
final remoteMessage = await FirebaseMessaging.instance.getInitialMessage();
if (remoteMessage == null) { // always null in android killed state
if (isUserOnboarded) {
openDashboardPage();
} else {
openOnBoardingPage();
}
} else {
if (navigatorKey.currentContext != null) {
Navigator.push(
navigatorKey.currentContext!,
MaterialPageRoute(
builder: (context) => DashboardPage(
catId: remoteMessage.data['category_id'],
showMain: remoteMessage.data['showMain'],
offer: remoteMessage.data['offer'],
)),
);
}
}
}
As this is the code used to check if app is launched from terminated state by click on push notification. I don't know where or what I'm doing wrong in this code. Any help would be appreciated.
Upvotes: 0
Views: 62