带有操作按钮和图像的颤动本地通知

Kas*_*nga 11 android push-notification ios dart-pub flutter

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

在此输入图像描述

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

Oma*_*att 7

flutter_local_notification 尚未支持此票证中提到的通知操作按钮。您可能需要考虑同时使用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'),
    ],
  );
}
Run Code Online (Sandbox Code Playgroud)

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

要侦听操作按钮按下的情况,请使用 actionStream 侦听器。您可以将其添加到屏幕上initState()

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