0

final data = { "notification": { "title": title, "body": body, }, "apns": { "payload": { "aps": {"badge": 1} } }, "to": pid };

2 Answers2

1

You have to use this type of Response when you get push notification then badges will show definitely. code response:-

{
    "notification": {
        "body": "This is an FCM notification message!",
        "title": "FCM Message",
        "badge":4
    },
    "priority": "high",
    "data": {
        "click_action": "FLUTTER_NOTIFICATION_CLICK",
        "id": "1",
        "status": "done"
    },

    "to": "eLk6p-WZ_kC-tZL60lRnp-:APA91bFhdwojQVVa-6wSCR9nTctBRZg0_Hx0ZACouKK2DsSjQzQX6EjrwCtJmWXfJzi2dO3t_ckcZmeWmoWoHMkgwrjMK5IAUJ3h1teBYD2mq-PjFb8-W3_PqMugl90e2fz7_AZYyTV-"
}
Jatin Sharma
  • 146
  • 1
  • 11
  • error on firebase cloud function - any idea what can I do? message: `Invalid JSON payload received. Unknown name "badge" at 'message.notification': Cannot find field. – Kobi Apr 25 '23 at 11:12
0

When you receive your payload data you have to update the badge manually when you are using Flutter.

Integrate this library in your code so it can manage it easily

All you have to do is read the badge that is coming inside the FCM body from the following code block and increase the badge depending on that number OR just increase the badge every time you receive a new notification:

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  print('Got a message whilst in the foreground!');
  print('Message data: ${message.data}');
});
Abdulrahman Alhayek
  • 1,626
  • 2
  • 15
  • 20