- First of all, this is a self-answering question.
- Second, I will try to describe in great detail the solution I have implemented for this situation.
- The problem posed: the badge attribute cannot be dynamically incremented
- source: https://firebase.google.com/docs/reference/admin/node/admin.messaging.NotificationMessagePayload#badge.
- So how do I get this badge property to automatically increment.? The solution I have answered is below, the 1st answer Also when you do this on multiple mobile devices what you need is:
IMPORTANT !!!
-
DO THIS WHEN YOU HAVE FOLLOWED THE STEPS IN THE ANSWER BELOW !!!
B1. Included badge number in each token of devices.
B2. change this when app init and generate fcm-token
FirebaseFirestore.instance.collection('fcm-token').doc(device_name).set({'device1_pt1': token_id,'number': 0});
B3. Put this then onmessage is call.(by onlauch, onresume, onmessage)
FirebaseFirestore.instance.collection('fcm-token').doc(device_name).update({'number': 0});