Ive been trying to build app that uses firebase cloud messaging i notice then when there is already a notif then i send another notif it replace the other one.
I want to make the notification stays there so the user can read all the notif, i tried unique tag to each notif i send but still doesnt work.
final data = {
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'status': 'done',
'message': title,
'body' : body,
};
try{
http.Response response = await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'), headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'key=MY_CODE'
},
body: jsonEncode(<String, dynamic>{
'notification': <String, dynamic> {'title': title, 'body': body ,'android_channel_id':'dbfood',"tag" : createTag(3)},
'priority': 'high',
'data': data,
'to': token
})
);
if(response.statusCode != 200){
print("Error");
}
}catch(e){
}
CodePudding user response:
in flutterLocalNotificationsPlugin.show make the id as a random number
await flutterLocalNotificationsPlugin.show(
1 Random().nextInt(1000 - 1),
//if static Id =>notification will be delete last notification received
"${event.notification!.title}",
"${event.notification!.body}",
platformChannelSpecifics,
);