Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase cloud messaging notif wont stack together

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){

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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,
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading