Update ongoing notification with Flutter

512

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.

Share:
512
flutterpiraat45
Author by

flutterpiraat45

Updated on December 01, 2022

Comments

  • flutterpiraat45
    flutterpiraat45 over 1 year

    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.

    • Syed Umair
      Syed Umair almost 2 years
      Did you find any solution?