How to get NotificationActionButton input data with flutter?

I'm trying to get notification action button data. That is when the user fill the input action, I get the data he entered.

Just like this.

enter image description here

I am using the awesome_notifcations flutter package.

This is my function to that creates new notification with input action for comment

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")
        ]);
  }

Here I just want to get the user's comment.

How to do so ?

Upvotes: 1

Views: 727

Answers (2)

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

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

Upvotes: 0

Felipe Vergara
Felipe Vergara

Reputation: 869

Do you need create listener to get new notifications like this:

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: Do you need replace with your data, this information is in docs (5. How to show Local Notifications)

Upvotes: 2

Related Questions