notifications_utils 0.2.1 copy "notifications_utils: ^0.2.1" to clipboard
notifications_utils: ^0.2.1 copied to clipboard

A Flutter package to get delivered notifications from the notification center on Android, iOS and MacOS and cancel them.

A Flutter package to get delivered notifications from the notification center on Android, iOS and MacOS and cancel them.

UNUserNotificationCenter is used on iOS and MacOS and NotificationManager on Android.

Usage #

Get notifications:

List<DeliveredNotification?> notifications = await NotificationsUtils().getDeliveredNotifications();
// `whereType` is used to take only not nullable notifications. 
// That's because `pigeon` package doesn't support non-nullable generic types.
for (final notification in notifications.whereType<DeliveredNotification>())
  print(
    "id: ${notification.id}\n"
    "threadIdentifier: ${notification.threadIdentifier}\n"
    "title: ${notification.title}\n"
    "body: ${notification.body}\n"
    "payload map: ${notification.payload}\n",
    "androidTag: ${notification.androidTag}\n",
  );

Cancel delivered notifications:

// On Android notification id is an integer and on iOS it's a string.
// That's why NotificationId class is used.
final NotificationId notificationId = NotificationId(
  /*optional*/ androidId: 1,
  /*optional*/ iosId: "someId",
  /*optional*/ androidTag: "someTag",
);
NotificationsUtils().removeDeliveredNotifications([notificationId]);

Why is it exists? #

Yeah, there is already great packages for notifications such as flutter_local_notifications and awesome_notifications.

But

  • the awesome_notifications package doesn't support canceling delivered notifications at all.
  • the flutter_local_notifications package can only cancel notifications that were created by it.
5
likes
160
pub points
65%
popularity

Publisher

unverified uploader

A Flutter package to get delivered notifications from the notification center on Android, iOS and MacOS and cancel them.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on notifications_utils