I am using flutter_local_notifications plugin to show notifications in Flutter and here is the initialization code:
Future<void> initializePlatformNotifications() async {
const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('icon');
final DarwinInitializationSettings initializationSettingsIOS = DarwinInitializationSettings(
requestSoundPermission: true,
requestBadgePermission: true,
requestAlertPermission: true,
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
final InitializationSettings initializationSettings = InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,
);
await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: (NotificationResponse notificationResponse) {
behaviorSubject.add(notificationResponse.payload!);
},
onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
);
}
the above code is working and the onDidReceiveNotificationResponse callback is called when the notification is clicked when the app is in the background but when the app is terminated and I click on the notification the callback is not called.
Should I use a different callback or my initialization code is missing something?
If your app is launched from terminated state by clicking on notification, you can get NotificationResponse via
flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails()
onDidReceiveNotificationResponse
only called when your app is paused, not terminated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With