.payload
on ActiveNotification
is just set for notifications that your app confirmed by way of flutter_local_notifications.present(..., payload: '...')
.
It does not learn the APNs/FCM payload of a distant push that iOS displayed for you. So for a push coming from FCM/APNs, activeNotifications[i].payload
might be null
.
Why? Within the plugin, payload
is a comfort string that the plugin shops contained in the iOS userInfo
when it creates the notification. Distant pushes proven by the OS don’t undergo the plugin, so there’s nothing to map into that discipline.
What to do as an alternative
Choice A (really helpful): carry knowledge by way of FCM knowledge
and browse it with firebase_messaging
.
{
"notification": { "title": "title", "physique": "physique" },
"knowledge": {
"display screen": "chat",
"id": "12345" // your customized fields
},
"apns": {
"payload": { "aps": { "content-available": 1 } }
}
}
FirebaseMessaging.onMessageOpenedApp.pay attention((RemoteMessage m) {
ultimate knowledge = m.knowledge; // {"display screen":"chat","id":"12345"}
// navigate utilizing this knowledge
});
ultimate preliminary = await FirebaseMessaging.occasion.getInitialMessage();
if (preliminary != null) { /* use preliminary.knowledge */ }
Choice B: Convert the distant push right into a native notification and fasten a payload.
- In foreground or in a background handler, learn
RemoteMessage.knowledge
, then name:
await flutterLocalNotificationsPlugin.present(
1001,
m.notification?.title,
m.notification?.physique,
const NotificationDetails(
iOS: DarwinNotificationDetails(),
android: AndroidNotificationDetails('default', 'Default'),
),
payload: jsonEncode(m.knowledge), //
Now getActiveNotifications()
will return an ActiveNotification
whose .payload
incorporates your JSON string.
Gotcha to keep away from: Including a payload
key inside apns.payload
doesn’t populate the plugin’s .payload
—that’s a distinct idea. Use RemoteMessage.knowledge
or explicitly set the payload
while you create a neighborhood notification.
Backside line: For FCM/APNs pushes, learn your customized information from RemoteMessage.knowledge
(and onMessageOpenedApp/getInitialMessage
). In the event you want .payload
from ActiveNotification
, you could present the notification regionally and go payload:
your self.