philiprehberger_notification_kit 0.2.0
philiprehberger_notification_kit: ^0.2.0 copied to clipboard
Unified notification scheduling with channels, priorities, and payload management
philiprehberger_notification_kit #
Unified notification scheduling with channels, priorities, and payload management
Requirements #
- Dart >= 3.5
Installation #
Add to your pubspec.yaml:
dependencies:
philiprehberger_notification_kit: ^0.2.0
Then run:
dart pub get
Usage #
import 'package:philiprehberger_notification_kit/notification_kit.dart';
final backend = MemoryDeliveryBackend();
final manager = NotificationManager(backend: backend);
manager.schedule(Notification(
title: 'Welcome',
body: 'Thanks for signing up!',
));
Channels and Priorities #
final alerts = NotificationChannel(
name: 'alerts',
importance: Importance.high,
sound: true,
);
manager.schedule(Notification(
title: 'Server Down',
body: 'Production is unreachable',
channel: alerts,
priority: Priority.urgent,
payload: {'incident_id': '42'},
));
Scheduled Delivery #
manager.schedule(Notification(
title: 'Reminder',
body: 'Meeting in 15 minutes',
deliverAt: DateTime.now().add(Duration(minutes: 15)),
));
// Later — deliver all due notifications
final delivered = await manager.deliverDue();
Notification Store #
final store = NotificationStore();
store.add(Notification(id: 'n1', title: 'Alert', body: 'text', priority: Priority.high));
store.add(Notification(id: 'n2', title: 'Info', body: 'text', priority: Priority.low));
final urgent = store.byPriority(Priority.high);
final channelNotifs = store.byChannel('alerts');
Notification Groups #
final store = NotificationStore();
store.add(Notification(title: 'Alert 1', body: 'text', groupId: 'alerts'));
store.add(Notification(title: 'Alert 2', body: 'text', groupId: 'alerts'));
final alertGroup = store.byGroup('alerts'); // 2 notifications
Delivery Status #
final n = Notification(title: 'Test', body: 'body');
print(n.deliveryStatus); // DeliveryStatus.pending
n.deliveryStatus = DeliveryStatus.delivered;
final pending = store.byStatus(DeliveryStatus.pending);
Repeating Notifications #
final scheduler = NotificationScheduler();
final ids = scheduler.scheduleRepeating(
Notification(title: 'Standup', body: 'Daily standup reminder', deliverAt: DateTime.now()),
interval: Duration(hours: 24),
count: 7,
);
Delivery Callbacks #
final manager = NotificationManager(
backend: backend,
onDeliver: (n) => print('Delivered: ${n.title}'),
);
API #
| Class / Method | Description |
|---|---|
Notification() |
Create a notification with title, body, channel, priority, payload, group, delivery status, and optional delivery time |
DeliveryStatus |
Enum for notification delivery status (pending, delivered, failed, retrying) |
NotificationChannel() |
Define a named channel with importance and sound settings |
NotificationStore.add() |
Add a notification to the in-memory store |
NotificationStore.get() |
Retrieve a notification by ID |
NotificationStore.remove() |
Remove a notification by ID |
NotificationStore.all() |
List all stored notifications |
NotificationStore.byChannel() |
Filter notifications by channel name |
NotificationStore.byPriority() |
Filter notifications by priority level |
NotificationStore.clear() |
Remove all notifications from the store |
NotificationStore.byGroup() |
Filter notifications by group ID |
NotificationStore.byStatus() |
Filter notifications by delivery status |
NotificationScheduler.schedule() |
Schedule a notification for delivery |
NotificationScheduler.cancel() |
Cancel a pending notification |
NotificationScheduler.pending() |
List all pending notifications |
NotificationScheduler.delivered() |
List all delivered notifications |
NotificationScheduler.deliverDue() |
Deliver all notifications whose time has arrived |
NotificationScheduler.reschedule() |
Change the delivery time of a pending notification |
NotificationScheduler.scheduleRepeating() |
Schedule a notification to repeat at a fixed interval |
NotificationManager.schedule() |
Schedule via the high-level facade |
NotificationManager.deliverDue() |
Deliver due notifications through the backend |
NotificationManager.cancel() |
Cancel a pending notification |
MemoryDeliveryBackend |
In-memory backend for testing |
Development #
dart pub get
dart analyze --fatal-infos
dart test
Support #
If you find this project useful: