![](/img/trans.png)
[英]scheduled notifications not showing (Flutter_local_notifications)
[英]flutter_local_notifications onNotificationReceived method - Flutter
基本上,我正在尋找一個onMessageReceived()
回調,但它適用於flutter_local_notifications,因此我可以處理數據並將其顯示給用戶。 這個插件只支持處理onNotificationTap()
動作。
Do Not Disturb
”,我應該如何處理該消息? 即使本地通知沒有顯示,我至少需要顯示一個覆蓋,由一些onMessageReceived()
函數觸發。在我的項目中,我正在使用:
flutter_local_notifications
包。在我的應用程序中安排事件時,過程如下:
POST
請求。onMessageReceived()
回調接收消息。'Got a message whilst in the foreground!'
信息。 這是由即時 FCM 數據消息觸發的。flutter_local_notifications
來安排通知。我沒有直接在 FCM 上安排通知,因為你不能從發布請求(奇怪)中做到這一點,但這會解決我所有的問題。
Overlay
notificationCount
基本上,我正在尋找一個onMessageReceived()
回調,但它適用於flutter_local_notifications,因此我可以處理數據並將其顯示給用戶。 此插件僅支持處理 onNotificationTap()` 動作。
這就是 FCM 所具有的而flutter_local_notifications
沒有的。 當我的應用收到通知時觸發:
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));
}
}
});
是的,據我所知,我們沒有與 FCM 相同的流選項來收聽系統托盤中的flutter_local_notifications
通知。
你可以檢查這個答案,它可能對你有幫助。
我想最后你最好在后端進行,並且再次通過 FCM 發送/接收這個預定的消息。
我不知道您正在使用的機制以及向用戶發送通知的功能,但如果它有關於調度的信息,您可以忽略向用戶發送通知。 根據您的代碼, scheduledDate
和formattedDate
知道它。 因此,在您發送通知的雲功能中,您可以代替發送通知、執行某些任務或觸發某些事情(類似於附加的答案),這將根據時間安排發送該通知。 然后在前端,例如,您可以在每次收到 FCM 通知時更新您的數據庫,因為您一開始並沒有發送它們,而是您實際上安排在計划的時間發送它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.