sometime the notification is delayed for no reason and then comes all together iam using https://pub.dev/packages/flutter_local_notifications https://pub.dev/packages/firebase_messaging
here is my code from cloud functions ( nodejs )
exports.messageTrigger = functions.firestore.document('/Messages/{messageID}').onCreate(
async (snapshot, context) => {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
var currentRoomUsers = snapshot.data().members;
currentRoomUsers.forEach( (userID) => {
db.collection('Users').doc(userID).get().then(async(doc)=>{
if(doc.exists && doc.id != snapshot.data().senderID){
const message = {
data: {
title: `New message from ${capitalizeFirstLetter(snapshot.data().room)}`,
body: snapshot.data().type == 'm.text' ? 'Sent a new message' : snapshot.data().type == 'm.start'? 'Invited you for a call' : snapshot.data().type == 'm.image' ? 'Sent an image' : 'Sent a new message'
},
tokens: doc.data()['Device_token'],
android: {
priority: 'high',
},
priority: "high",
}
await admin.messaging().sendMulticast(message);
}else {
console.log("No such document!");
}
}).catch((error)=>{
console.log("Error getting document:", error);
});
}
);
}
);