https://github.com/maksimka101/notifications_utils
A Flutter package to get delivered notifications from the notification center on Android and iOS and cancel them.
https://github.com/maksimka101/notifications_utils
Last synced: about 1 month ago
JSON representation
A Flutter package to get delivered notifications from the notification center on Android and iOS and cancel them.
- Host: GitHub
- URL: https://github.com/maksimka101/notifications_utils
- Owner: Maksimka101
- License: mit
- Created: 2023-07-19T12:31:24.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T10:03:03.000Z (10 months ago)
- Last Synced: 2025-03-29T21:02:42.267Z (2 months ago)
- Language: Swift
- Homepage:
- Size: 300 KB
- Stars: 7
- Watchers: 1
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
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:
```dart
List 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())
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:
```dart
// 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](https://pub.dev/packages/flutter_local_notifications) and
[awesome_notifications](https://pub.dev/packages/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.