Description
Bug report
Describe the bug
Firebase Messaging library appears to not handle data messages. Data messages are converted to notification messages as part of the remote message parsing that the library does after receiving the notification from firebase.
Steps to reproduce
Steps to reproduce the behavior:
- Add firebase_messaging library to project and configure
- Put the app in the background
- Send a data notification to the app. I am using this to send the push:
curl --location --request POST 'https://fcm.googleapis.com/fcm/send' \
--header 'Content-Type: application/json' \
--header 'Authorization: key=<REDACTED> \
--data-raw '{
"registration_ids": ["<REDACTED>"],
"data": {
"foobar": "bazbar"
}
}'
The above data notification is attempted to be delivered to the system tray as a notification message type, but it fails with this error:
NoSuchMethodError: The method 'call' was called on null.
Receiver: null
Tried calling: call(_LinkedHashMap len:1)
If I foreground the app and send the notification again, this is what I get back in the onMessage
callback.
{notification: {title: null, body: null}, data: {foobar: bazbar}}
This payload shouldn't have a notification key within the payload. This is why the logs display an error when the app is backgrounded. The system is trying to create a notification with null body/title. Looks like the Firebase Messaging library is adding the notification key, even when the notification key is null in the message received from Firebase. I found what looks to be the culprit.
Looks like the parseRemoteMessage
function appends a notification object to the map, even when remoteMessage.getNotification()
is null.
Expected behavior
Data messages sent to the app with the plugin registered are still handled as data messages.
Branch with fix
https://github.com/james-airspace/flutterfire/tree/fix-3696