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.
You may want to consider using awesome_notifications plugin in the meantime since it has support for notification buttons. 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 achieve an image on local notification, first add the awesome_notifications Flutter package by adding the following lines in pubspec. yaml file. awesome_notifications is the best flutter package we got to show local notifications in the Flutter app.
Displaying a notification in Flutter To display a notification, we need to create a platform-specific NotificationDetails instance, which takes in arguments that are unique to each platform. AndroidNotificationDetails handles the configuration of notifications in Android devices.
To achieve an image on local notification, first add the awesome_notifications Flutter package by adding the following lines in pubspec.yaml file. awesome_notifications is the best flutter package we got to show local notifications in the Flutter app. How to add Image from Assets folder on Local Notification?
If your application needs the ability to schedule full-screen intent notifications, add the following attributes to the activity you're opening. For a Flutter application, there is typically only one activity extends from FlutterActivity. These attributes ensure the screen turns on and shows when the device is locked.
Below are some button widgets that are shipped with Flutter SDK: Actions are assigned using onPressed () function. We are going to see two methods to assign Actions. Note: We are not going to use any other dependencies for this application. Using function reference.
Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. Flutter provides a number of prebuilt widgets to use. There are different types of Button widgets that are provided by the Flutter SDK.
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}');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With