In Flutter Web, when a Firebase notification is received and the app is in front, I do have my "onMessage" handler executed. However, when the app is in the background, I do see the Chrome notification with the preview of the message displayed, but nothing is executed in the app. I can't find a way to have the service worker "ping" the running application, or even simply run independent Flutter code to set something in the SharedPreferences so the user gets the full message when she opens the app.
This work as intended in Android for instance.
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
if (message.notification != null) {
SharedPreferences.getInstance().then((SharedPreferences p) {
p.setString("notification", message.notification.body.toString());
});
}
}
//[... initialization code : ...]
String notif = prefs.getString("notification");
if (notif != null) {
showSnack(notif, duration: Duration(days: 365));
prefs.remove("notification");
}
FirebaseMessaging.onBackgroundMessage(
_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if (message.notification != null) {
showSnack(message.notification.body.toString(),
duration: Duration(days: 365));
}
});
Aucun commentaire:
Enregistrer un commentaire