Flutter Awesome通知无法将方法绑定到操作按钮

dy1byipe  于 2022-11-30  发布在  Flutter
关注(0)|答案(2)|浏览(168)

我正在开发一个应用程序,它需要响应通知。我可以在收到通知时显示按钮。但是,我无法将任何方法绑定到它。下面是我的代码:

Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message)  async {
  await Firebase.initializeApp();
    AwesomeNotifications().createNotification(
          content: NotificationContent(
              id: 10,
              channelKey: 'basic_channel',
              title: 'Simple Notification',
              body: 'Simple body'),
          actionButtons: [
            NotificationActionButton(
                label: 'TEST',
                enabled: true,
                buttonType: ActionButtonType.Default,
                key: 'test',
                )
          ]);
    print("Background message service");
  }

感谢您的帮助!

ilmyapht

ilmyapht1#

您应该创建一个事件流并侦听如下所示的事件:

AwesomeNotifications().actionStream.listen((event) {
      print('event received!');
      print(event.toMap().toString());
      // do something based on event...
    });
rur96b6h

rur96b6h2#

为新版本中的任何人更新。您可以按照文档中的说明,通过各种其他操作来处理对通知的点击。以下是我所做的。文档

class NotificationController {
  /// Use this method to detect when the user taps on a notification or action button
  @pragma("vm:entry-point")
  static Future<void> onActionReceivedMethod(ReceivedAction receivedAction) async {
    // Your code goes here

    /// Handles regular notification taps.
    if(receivedAction.actionType == ActionType.Default){
      if(receivedAction.id == 17897583){
        // do something...
      }
    }
  }
}

相关问题