Hey fellow flutter devs,
My app has some chat functionality and I am sending push notifications via Firebase Cloud Functions and then handle them in onMessage, onLaunch and onResume. It works all as intended.
But what my problem is: When the user is currently viewing the Chat, I dont want the user to see a notififcation, since I am already using a stream listener and the user sees the new messages popping up! So no need to get notified here.
My Code for onMessage in CloudMessaging.configure():
onMessage: (Map<String, dynamic> message) async {
print(message);
String chatID = message['data']['chatID'].toString();
//I want to do something like this:
//var routeArguments = ModalRoute.of(naviagtorkey.getCurrentContext).settings.arguments;
//if (routeArguments.contains(chatID)){return;}
String id = message['data']['id'].toString();
if (id != _auth.currentUser.uid) { //this makes sure user who sends message doesnt see get notfied
showOverlayNotification((context) {
return Card(//removed for clarification)
);
}
My Chat class is constructed with a chatID, so if I could somehow access the current Route and see its arguments (its chatID), then I should be able to NOT show any notification when current route arguments equal message['data']['chatID']. Am I wrong? How could I do that. My commented idea just fails quietly.