Reputation: 51
Currently we are using the awesome notifications package to display a notification in our Flutter app. We want to constantly update the contents of this notification. Specifically, we want to display a timer within the notification. For now we create a new notification every second with the altered content. This means a lot of notifications are constantly created and removed.
Is there a way to update the existing notification instead of constantly creating a new one?
This with the package we are currently using or a different Flutter package. Ideally we would like to prevent having to use platform specific coding.
Upvotes: 3
Views: 5580
Reputation: 810
I'm not aware of awesome_notifications
package, but I've tried flutter_local_notifications
and it uses chronometer that can work as a timer for your notification. It places the timer at the summary area of the notification, not in the body, I suppose.
This is the code from the sample project:
Future<void> _showNotificationWithChronometer() async {
final AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
'your channel id',
'your channel name',
channelDescription: 'your channel description',
importance: Importance.max,
priority: Priority.high,
when: DateTime.now().millisecondsSinceEpoch - 120 * 1000,
usesChronometer: true,
);
final NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0, 'plain title', 'plain body', platformChannelSpecifics,
payload: 'item x');
}
Also check out the full example code here and explore the rest of the possibilities.
Upvotes: 3