Push Notification received but not displayed (Flutter / Dart)

2,174

This is a bit of a silly addition but I was having the same problem and realized my Do-Not-Disturb was turned on. I didn't think anything of it however because I had turned it off.

However, I guess because it was on a schedule it was still blocking notifications. I now have them working properly at the time of typing this - on iOS 13.5 displaying in the background.


Resources

https://fireship.io/lessons/flutter-push-notifications-fcm-guide/

https://pub.dev/packages/firebase_messaging

https://github.com/fireship-io/192-flutter-fcm-push-notifications/blob/master/lib/main.dart

Share:
2,174
Florian K
Author by

Florian K

I create apps for clients or myself. Flutter for life !

Updated on November 23, 2022

Comments

  • Florian K
    Florian K over 1 year

    Notification in json is well received by the phone receiver and there is a print with json content in 'onMessage'. However no notifications is shown on the screen. Here is the json code sent :

        var client = http.Client();
    
        var jsonData = json.encode({
                    "to": "/topics/$userId",
                    "notification": {
                      "body": "$notificationText",
                      "title": "Title",
                    },
                    "data": {
                      "click_action": "FLUTTER_NOTIFICATION_CLICK",
                      "sound": "default",
                      "status": "done",
                      "screen": "ListPostsScreen",
                    },
                    "content_available": true,
                    "priority": "high",
                  });
    
                  var headers = {
                    'Authorization': "key=$key",
                    'Content-Type': 'application/json',
                  };
    
        var response = await client.post(url, headers: headers, body: jsonData);
    
        print(response.body);
    

    firebaseMessaging in home screen :

    final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
        firebaseMessaging.configure(
          onMessage: (Map<String, dynamic> message) async {
            print("onMessage: $message");
          },
          onLaunch: (Map<String, dynamic> message) async {
            print("onLaunch: $message");
          },
          onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
          onResume: (Map<String, dynamic> message) async {
            print("onResume: $message");
          },
        );
    

    This is the intent-filter in main/AndroidManifest.xml

    <intent-filter>
      <action android:name="FLUTTER_NOTIFICATION_CLICK" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    

    My pubspec.yaml packages :

      firebase_messaging: ^5.1.6
    

    Did I miss something ? Thank you.

    • Francisco Javier Snchez
      Francisco Javier Snchez about 4 years
      What are you using to send the notifications? And to receive them? Are you using any package?
    • Florian K
      Florian K about 4 years
      I use firebase cloud messaging : firebase_core: ^0.4.0+9, firebase_analytics: ^5.0.2, firebase_auth: ^0.14.0+5; firebase_messaging: ^5.1.6,
    • Francisco Javier Snchez
      Francisco Javier Snchez about 4 years
      What is the message you see when the app crashes?
    • Florian K
      Florian K about 4 years
      It says that the app stopped working. Do you think I can see error message in the console, on the phone which receives the notification ? When I did the test, only mobile which send notifications was in USB so I did not see error message in other side
    • Francisco Javier Snchez
      Francisco Javier Snchez about 4 years
      Try to connect the phone that crashes and see what is the error when it crashes. Maybe it has nothing to do with the notification.