簡體   English   中英

如何折疊 Flutter 中的通知? 使用本地推送通知插件和 CloudFunctions

[英]How can I collapse notification in Flutter? using Local Push Notification plugin and CloudFunctions

我正在使用雲 function 通過使用設備令牌發送通知。

    const payload: admin.messaging.MessagingPayload = {
        notification: {
            title: `updatedBy: ${updatedBy}`,
            body: `nova messagem ${increment}`,
        },

    }
    return fcm.sendToDevice(userToken, payload, options).then((value) => {
        console.log(value.results);
    }).catch((error) => {
        console.log(error);
    })

但是,所有通知都被打亂了,我非常想管理這些停留在系統托盤中的通知,無論如何我可以使用這些插件來調節具有這種“復雜性”的通知嗎? (本地推送通知、FCM、cloudfunctions)不使用本機代碼(kotlin、android)? 因為我不知道 android 結構是如何工作的......

我可以使用 cancelAll(本地推送通知)

FlutterLocalNotificationsPlugin.cancelAll()

來自本地推送通知: https://pub.dev/documentation/flutter_local_notifications/latest/

但是太不靈活了

我還可以使用特定“ID”的取消通知,但我不知道如何獲取該通知“id”

FlutterLocalNotificationsPlugin.cancel(notificationId)

那么,如何解決這個問題呢?

這樣我就可以明智地刪除我想要的任何通知,但基本上,我只想折疊相同類型的通知,比如在 Whatsapp 上,當一個人向你發送超過 1 條消息時,在系統托盤中,只有一個通知說“他”發送了不止一條消息(而不是一大堆通知)。

我剛剛看了https://github.com/chetdeva/collapsing-notifications/tree/a5e8867e24f53ff8caca761c7faa13242c607dba

此 github 代碼適用於文章https://medium.com/fueled-engineering/collapsing-fcm-notification-like-a-pro-102a4946b350

如果在 flutter 項目中實施起來不太困難,那將是完美的,我還查看了這里的每個帖子,在 stackoverflow 中,看到沒有人回答過這個問題

[編輯]:我不能使用的原因

FlutterLocalNotificationsPlugin.cancelAll()

這是因為我正在使用 fcm 方法來監聽通知,我試圖將該方法放在一些 fcm 監聽器中但沒有成功。

_firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print('on message $message');
      },
      onResume: (Map<String, dynamic> message) async {
        print('on resume $message');

      },
      onLaunch: (Map<String, dynamic> message) async {
        print('on launch $message');
      },
    );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM