如何用flutter获取NotificationActionButton输入数据?

问题描述 投票:0回答:2

我正在尝试获取通知操作按钮数据。即当用户填写输入动作时,我得到他输入的数据。

就像这样。

我正在使用 awesome_notifcations flutter 包。

这是我的功能,用于创建带有评论输入操作的新通知

Future<void> create({
    required String key,
    required String title,
    required String body,
    required String bigPicture,
  }) async {
    await _notiff.createNotification(
        content: NotificationContent(
          id: DateTime.now().millisecondsSinceEpoch.remainder(10),
          channelKey: key,
          title: title,
          body: body,
          bigPicture: bigPicture,
          notificationLayout: NotificationLayout.BigPicture,
        ),
        actionButtons: [
          NotificationActionButton(
              buttonType: ActionButtonType.InputField,
              enabled: true,
              label: "Comment",
              key: "COMMENT_BUTTON_KEY")
        ]);
  }

这里我只是想得到用户的评论。

如何做到这一点?

android flutter push-notification android-notifications
2个回答
2
投票

您是否需要创建侦听器来获取这样的新通知:

AwesomeNotifications().actionStream.listen(
    (ReceivedNotification receivedNotification){

        Navigator.of(context).pushNamed(
            '/NotificationPage',
            arguments: {
                // your page params. I recommend you to pass the
                // entire *receivedNotification* object
                id: receivedNotification.id
            }
        );

    }
);

PD:您是否需要替换为您的数据,此信息在文档中(5.如何显示本地通知)


0
投票

AwesomeNotifications().actionStream.listen( (收到通知收到通知){

   if (event.buttonKeyPressed == "COMMENT_BUTTON_KEY"){
     String userComment = event.buttonKeyInput;}

);

© www.soinside.com 2019 - 2024. All rights reserved.