Basically, I am looking for an onMessageReceived()
callback but that works with flutter_local_notifications so I can handle and show the data to the user. This plugin only supports handling the onNotificationTap()
action.
Do Not Disturb
on? Even if the local notification doesn't show, I need to show an Overlay at least, triggered by some onMessageReceived()
function.In my project I am using:
flutter_local_notifications
package.When an event is scheduled in my app, the process is the following:
POST
request to FCM with data only message.onMessageReceived()
callback.'Got a message whilst in the foreground!'
message. This was triggered by the instant FCM data message.flutter_local_notifications
to schedule a notification.I don't schedule a notification directly on FCM because you can't do that from a post request (weird), but that would solve all my problems.
Overlay
with the notification, in case of the user being in the foregroundnotificationCount
in my Firebase Realtime DatabaseBasically, I am looking for an onMessageReceived()
callback but that works with flutter_local_notifications so I can handle and show the data to the user. This plugin only supports handling the onNotificationTap()` action.
This is what FCM has that flutter_local_notifications
doesn't. Triggered when a notification is received by my app:
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
print('Got a message whilst in the foreground!');
[...]
if (scheduledDate != null) {
//using flutter_local_notifications
sendScheduledLocalNotification(itemTitle, 'Due Today', formattedDate);
//this notification, received at a later date, cannot be processed with this same function because it doesn't use FCM
}
//only shown with instant notifications (not scheduled)
if (notification != null) {
showOverlayNotification((context) {
return LocalNotificationOverlay(
title: notification.title!,
subtitle: notification.body!,
imageUrl: notification.imageUrl!,
);
}, duration: Duration(seconds: 3));
}
}
});
Yes, as far as I know we don't have the same stream option to listen to the notifications in the system tray for flutter_local_notifications
as we have for FCM.
You can check this answer, It might help you.
I guess in the end you'd better do it in the back-end, and again this scheduled message being send/received via FCM.
I don't know about the mechanism that you're using and the function that sends the notification to user, but you can ignore sending notification to user if it has information about scheduling. Based on your code, scheduledDate
and formattedDate
are aware of it. So in your cloud function that sends the notifications you can instead of sending a notification, doing some task or triggering something(similar to the attached answer) and this will schedule sending that notification based on its time. Then in front-end for example you can update your databases every time you get a notification from FCM, because you didn't send them in the first place and you actually scheduled sending them in the planed time.