繁体   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