How to hide a new message notification when user is actively chatting with the sender in flutter
I have implemented a similar feature in my app. This is what I did. I am using flutter and hive for local storage.
Do this when entering chat view
Hive.box("settings").put("currentChatId", xxx)
And on popping the page, set it to null again
On receiving notifications, before showing local notification you can just use .get("currentChatId")!= null && id==notificationId
to check if it should show it or not.
Sinshaw Demisse
A passionate software engineer Java, Springboot, Flutter, firebase, AWS
Updated on December 24, 2022Comments
-
Sinshaw Demisse over 1 year
I am implementing a chat feature in my flutter app. I use FCM to send a notification when a new message comes. I propagate the FCM message to flutter local notification when the notification came while the app is in the foreground. My problem is I don't want to show the local notification when the user is actively chatting with the sender.
I have firebase messaging configuration in app.dart and I have another stateful widget to show the message details and chat. I will get
fromUid
from notification data. I have also open chat message UID's in the message details widget. I am trying to compare these two UIDs values from notification and message detail widget and if the UIds are the same don't notify.I try using change notifier and RouteObserver but it's not working fine. I will love any help and recommendations.
-
Shlok Jain about 3 yearsdid you get the answer? @Sinshaw Demisse
-