Flutter firebase messaging v9.0.0 - Not firing events

3,813

I came across this exact same issue after migrating and upgrading to 9.0.0.

There is a minor issue with 9.0.0 plugin. The fix can be found here: https://github.com/FirebaseExtended/flutterfire/issues/4949

To cut a long story short, if you navigate to the definition of the factory RemoteMessage.fromMap() Using Cmd+Click or Ctrl+Click while hovering over the RemoteMessage class with the mouse), in the return statement, change contentAvailable: map['contentAvailable'], to contentAvailable: map['contentAvailable']??false.

Notifications are now working for me again now. This should work for you until the plugin is fixed.

Share:
3,813
Santi
Author by

Santi

Updated on December 28, 2022

Comments

  • Santi
    Santi over 1 year

    I have an app that was using firebase messaging 7.0.3 and all worked perfectly. But when I migrated to firebase messaging 9.0.0, the push notifications are not being handled.

    I know that the app is correctly linked to firebase and cloud messaging because in background I see the push notification comming, the problem is when I click that notification the app don't handle this event. Also, when the app is in foreground, the event of receiving the notification is not being triggered.

    Specifically, the functions FirebaseMessaging.onMessage and FirebaseMessaging.onMessageOpenedApp are not working. My code is:

    FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      print("notification: message");
    }); 
    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
      print("notification: resume");
    });
    

    The prints are never called, and if I put some more code inside isn't executed too.

    I also call FirebaseMessaging.getToken and I can get the token, plus when the app is in background I get the push notification, so is not a link problem with firebase. In the logs, when I receive the push I can see a message saying: Broadcast received for message. So I assumed that the push is arriving in all the occasions, and I am doing something wrong in the code.

    I tested all cases in Android and iOS physical devices.

    Someone know why this occurs?