I am student who is studying computer programming in Canada. Nowadays , I am making the app as my side project with flutter/firebase.
In my app chat function is included. The problem that I am facing is how to increment badge number and keep it if the message is not read.
I attached the picture of my Message data structure in the firebase.
and below code is the firebase function code. For now I am pushing the notification with this code. I am getting the notification successfully , but the problem is the how to count badge number of the app icon. As you can see in the notification badge number is '1'. Whenever I push the notification, that number is overriding previous number. I think this is wrong way, what I am expecting, if the value isMessageRead in the firebase database increment badge number. I am just wondering the logical way , or any other source that I can study that can explain how to count the Icon badge Number.
For now I have no idea how to manage badge number.
Thanks for reading,
I am waiting for your reply.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.onCreateMessage = functions.firestore.document('/Chat/{currentUserID}/UserList/{anotherUserID}/Messages/{message}')
.onCreate(async (snap, context) => {
const currentUserID = context.params.currentUserID;
const anotherUserID = context.params.anotherUserID;
console.log(currentUserID);
console.log(anotherUserID);
if (currentUserID == snap.data().recieverID) {
return admin.messaging().sendToTopic(`${currentUserID}`, {
notification: {
title: snap.data().senderID,
body: snap.data().message,
clickAction: 'FLUTTER_NOTIFICATION_CLICK',
sound: 'default',
badge: '1'
}
});
}
});

