【问题标题】:Flutter local notification with action buttons and image带有操作按钮和图像的 Flutter 本地通知
【发布时间】:2021-08-19 18:43:35
【问题描述】:

我想通过 Firebase 消息推送此类通知。现在是我使用https://pub.dev/packages/flutter_local_notifications 这个包的普通通知的时候了。但我没有看到有一种方法可以添加操作按钮。以及我想在 45 秒后删除此通知或使用另一条 firebase 消息。我也在为 android 和 ios 开发这个应用程序。如果我的问题不清楚或需要更多信息,请随时发表评论。

我在 Stackoverflow 上看到了一个类似的问题。

【问题讨论】:

    标签: android ios flutter push-notification dart-pub


    【解决方案1】:

    flutter_local_notification 尚未支持ticket 中提到的通知操作按钮。您可能需要同时考虑使用awesome_notifications 插件,因为它支持通知按钮。

    要使用操作按钮显示通知,只需使用

    
    void _showNotificationWithButton() {
      AwesomeNotifications().createNotification(
        content: NotificationContent(
            id: 10,
            channelKey: 'basic_channel',
            title: 'Simple Notification',
            body: 'Simple body'),
        actionButtons: <NotificationActionButton>[
          NotificationActionButton(key: 'yes', label: 'Yes'),
          NotificationActionButton(key: 'no', label: 'No'),
        ],
      );
    }
    

    然后,您可以通过在 NotificationActionButton 上添加图标属性来为操作按钮添加图标。图标应该是资产中映射的图像的字符串资源。

    要侦听 Action Button 按下,请使用 actionStream 侦听器。你可以在屏幕的initState()添加这个

    AwesomeNotifications().actionStream.listen((receivedNotification) {
      // prints the key of the NotificationActionButton pressed
      debugPrint('Notification key pressed: ${receivedNotification.buttonKeyPressed}');
    });
    

    【讨论】:

      猜你喜欢
      • 2020-06-09
      • 2017-12-18
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多