'Flutter show app icon badge on push notification

I'm looking for a way to show an app icon badge when a user receives a push notification.

I'm using the Firebase_messaging plugin for flutter for the handling of the push notifications and flutter_app_badger for the app icon badges. But I want to combine the two so that the number is set on the icon without opening the app. Is it possible to make this happen? Or am I overlooking something obvious from the firebase_messaging plugin?

Sorry for the horrible explanation. I hope someone can help me with this issue.



Solution 1:[1]

App icon badge depends on the Application Launcher

Some of the Android Application Launcher includes this functionality by default, You can check this on Settings->Apps->Notification Attached image

FYI

Solution 2:[2]

My suspicion is that you have an icon that isn't compatible with the icon guidelines in your device. I suggest trying https://pub.dev/packages/flutter_launcher_icons to make icons for your device.

Solution 3:[3]

I think you try to create stream when run app to real time listen doc changes in Firestore. Read here How to listen for document changes in Cloud Firestore using Flutter?

And the icon can be update in background but without opening app is impossible I think.

Solution 4:[4]

I don't have a direct answer because I haven't encountered this issue before, but this might fix your problem

Ensure that you have defined the icon for your application properly - for flutter, here are the steps you should have:

  1. Import the package into your pubsec.yaml file - it should be called flutter_launcher_icons: "^0.8.0" and imported under the dev-dependencies section of the pubspec.yaml file.

  2. After the dev-dependencies section, add a new section for flutter icons as so: flutter_icons: ios: true android: true image_path_ios: "{Icon File Path}" image_path_android: "{Icon File Path}"

Hopefully this helps, and good luck with fixing your issue!

Solution 5:[5]

Using https://pub.dev/packages/firebase_messaging for notifications , for Android Background notifications you can add this in your AndroidManifest.xml file in your application tag. And make sure you have androidlogo.png (this is example name) present in your drawable folder.

<application>
<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/androidlogo" />
</application>

In case of foreground notifications, you must be using Flutter Local Notifications, so you can provide the same while initializing like

var initializationSettingsAndroid = new AndroidInitializationSettings('androidlogo');
flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onNotificationClicked);

And for application icon you can use this library https://pub.dev/packages/flutter_launcher_icons which is also suggested by answers above.

In case of iOS, your launcher icon will your notification icon.

And for display of badge icon you can use https://pub.dev/packages/flutter_app_badger. (For supported phones).

So using all this you will get both app icon with badge and notification icon as your app icon (or specified by you).

Solution 6:[6]

You can control the badge count from the notification payload.

If you send a notification manually from Firebase Console, you can set the badge count on Additional options step:

How to Set App Icon Badge from Firebase Cloud Messaging Console

If you send it programmatically, add this payload (iOS example):

{"aps":{"alert":"Enter your message","badge":1,"sound":"default"}}

For more payload options, check out FCM documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharmesh Mansata
Solution 2 frogsam5
Solution 3
Solution 4 Sashv D
Solution 5 Tanmay Pandharipande
Solution 6 Andrey Gordeev