I'm sending FCM notification from my cloud functions to my flutter app.
I don't want the FCM system to handle notification display when the app is in background or terminated. Hence, I'm sending the data to show in notification in the data
key instead of the notification
key.
Cloud Functions:
await admin.messaging().sendMulticast({
tokens: userFCMTokens,
data: {
title: "Notification title to display",
body: "Notification body to display",
},
android: {
notification: {
channelId: "some_channel_id",
},
},
});
On the client side (i.e. Flutter app) I'm receiving/handling the FCM messages and displaying them with the awesome_notifications plugin.
Flutter:
AwesomeNotifications().createNotification(
content: NotificationContent(
id: message.hashCode,
channelKey: message.notification?.android?.channelId,
title: message.data['title'],
body: message.data['body'],
bigPicture: message.data['imageUrl'],
wakeUpScreen: true,
notificationLayout: NotificationLayout.BigPicture,
),
actionButtons: (message.data['actions'] as List<Map>?)
?.map(
(e) => NotificationActionButton(
key: e['key'],
label: e['label'],
),
)
.toList(),
);
This setup works properly when the app is in foreground but when in background or terminated it shows 2 notification. One proper and one totally empty notification.
I don't want the FCM SDK system to handle the notification hence I'm using data
instead of notification
but then this problem arises.