Flutter local notification with action buttons and image
flutter_local_notification has yet to have support for Notification Action Buttons as mentioned on this ticket. You may want to consider using awesome_notifications plugin in the meantime since it has support for notification buttons.
To show notification with Action Button, simply use
void _showNotificationWithButton() {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'basic_channel',
title: 'Simple Notification',
body: 'Simple body'),
actionButtons: <NotificationActionButton>[
NotificationActionButton(key: 'yes', label: 'Yes'),
NotificationActionButton(key: 'no', label: 'No'),
],
);
}
You can then add the icon for the Action Button by adding the icon property on NotificationActionButton. The icon should be a String resource of the image mapped in the assets.
To listen for the Action Button press, use an actionStream listener. You can add this on the screen's initState()
AwesomeNotifications().actionStream.listen((receivedNotification) {
// prints the key of the NotificationActionButton pressed
debugPrint('Notification key pressed: ${receivedNotification.buttonKeyPressed}');
});
Comments
-
Kasun Hasanga over 1 year
I want to push this type of notification with a firebase message. Now the time I am using a normal notification with https://pub.dev/packages/flutter_local_notifications this package. But I didn't see there is a way to add an Action button. As well as I want to remove this notification after 45second or with another firebase message. as well I'm developing this application for android and ios. If my question is not clear or need more information please free to comment.
I saw a Similar Question on Stackoverflow.
-
Sanjayrajsinh about 2 yearsthis notification always shows in notificaiton tray , Its not shows on top of screen
-
Gk Mohammad Emon about 2 yearsreceivedNotification.buttonKeyPressed is not found