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.
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.
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);
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
},
);
© 2022 - 2024 — McMap. All rights reserved.