Unified notification scheduling with channels, priorities, and payload management
dart pub add philiprehberger_notification_kitUnified notification scheduling with channels, priorities, and payload management
Add to your pubspec.yaml:
dependencies:
philiprehberger_notification_kit: ^0.1.0
Then run:
dart pub get
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!',
));
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'},
));
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();
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');
final manager = NotificationManager(
backend: backend,
onDeliver: (n) => print('Delivered: ${n.title}'),
);
| Class / Method | Description |
|---|---|
Notification() | Create a notification with title, body, channel, priority, payload, and optional delivery time |
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 |
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 |
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 |
dart pub get
dart analyze --fatal-infos
dart test
If you find this project useful: