Flutter local notification with action buttons
Asked Answered
L

4

8

I tried flutter local notification plugin in my flutter project its work fine on simple notifications but I need functionality of notifications with action buttons pls help me or suggest me to achieve this function.

Laurenelaurens answered 25/2, 2020 at 13:41 Comment(0)
E
9

Unfortunately, the flutter_local_notifications plugin does not support action buttons yet. There´s a feature request to add this.

I don´t know of any other plugins that support this, so i think right now the only possibility is to create your own custom plugin and develop it in native iOS code.

Eckel answered 25/2, 2020 at 13:57 Comment(2)
Thank you Josh I searched all.the resources but no way to achieve this. So started to create my own pluginLaurenelaurens
@ThulasiRaman did you write an own plugin? If so, would you share it?Rhinology
N
3

use awesome_notifications: ^0.0.6+7 package

Nonplus answered 29/5, 2021 at 6:41 Comment(0)
E
2

awesome_notifications can be used to push notifications with action buttons.

Explanation:
This can be done by customizing the data (Json) received like:

{
    "to" : "[YOUR APP TOKEN]",
    "mutable_content" : true,
    "content_available": true,
    "priority": "high",
    "data" : {
        "content": {
            "id": 100,
            "channelKey": "big_picture",
            "title": "Huston!\nThe eagle has landed!",
            "body": "A small step for a man, but a giant leap to Flutter's community!",
            "notificationLayout": "BigPicture",
            "largeIcon": "https://media.fstatic.com/kdNpUx4VBicwDuRBnhBrNmVsaKU=/full-fit-in/290x478/media/artists/avatar/2013/08/neil-i-armstrong_a39978.jpeg",
            "bigPicture": "https://www.dw.com/image/49519617_303.jpg",
            "showWhen": true,
            "autoCancel": true,
            "privacy": "Private"
        },
        "actionButtons": [
            {
                "key": "REPLY",
                "label": "Reply",
                "autoCancel": true,
                "buttonType":  "InputField"
            },
            {
                "key": "ARCHIVE",
                "label": "Archive",
                "autoCancel": true
            }
        ],
        "schedule": {
            "timeZone": "America/New_York",
            "hour": "10",
            "minute": "0",
            "second": "0",
            "millisecond": "0",
            "allowWhileIdle": true,
            "repeat": true
        }
    }
}

and pushing notification with that messageData like:

AwesomeNotifications().createNotificationFromJsonData(yourReceivedMapData);
Enneastyle answered 21/8, 2021 at 14:40 Comment(0)
L
0

You can use awesome_notifications package.

This how to create a notification with action buttons in it:

AwesomeNotifications().createNotification(
  content: NotificationContent(
      id: 10,
      channelKey: 'basic_channel',
      title: 'Simple Notification',
      body: 'Simple body',
  ),
  actionButtons: <NotificationActionButton>[
    NotificationActionButton(key: 'accept', label: 'Accept'),
    NotificationActionButton(key: 'reject', label: 'Reject'),
  ],
);

You can add icons, text fields and so many other things. Look here for more.

And to listen for the tapped button, here's the code:

AwesomeNotifications().actionStream.listen(
  (ReceivedAction receivedAction) {

    if (receivedAction.buttonKeyPressed == 'accept') {
      //Your code goes here
    } else if (receivedAction.buttonKeyPressed == 'reject') {
      //Your code goes here
    }

    //Here if the user clicks on the notification itself
    //without any button

  },
);
Lone answered 26/7, 2022 at 16:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.