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.4.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 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
final n = Notification(title: 'Test', body: 'body');
print(n.deliveryStatus); // DeliveryStatus.pending
n.deliveryStatus = DeliveryStatus.delivered;
final pending = store.byStatus(DeliveryStatus.pending);
final scheduler = NotificationScheduler();
final ids = scheduler.scheduleRepeating(
Notification(title: 'Standup', body: 'Daily standup reminder', deliverAt: DateTime.now()),
interval: Duration(hours: 24),
count: 7,
);
final template = NotificationTemplate(
titleTemplate: 'Hello {{name}}',
bodyTemplate: 'Your order {{orderId}} is {{status}}',
priority: Priority.high,
);
// Extract placeholder names
print(template.placeholders); // [name, orderId, status]
// Build a notification with variable substitution
final notification = template.build({
'name': 'Alice',
'orderId': '42',
'status': 'shipped',
});
final limiter = RateLimiter(cooldown: Duration(seconds: 30));
final manager = NotificationManager(
backend: backend,
rateLimiter: limiter,
);
// Rapid deliveries on the same channel are throttled
final store = NotificationStore();
// Remove all low-priority notifications
final removed = store.removeWhere((n) => n.priority == Priority.low);
print('Removed $removed notifications');
final store = NotificationStore();
final now = DateTime.now();
store.add(Notification(
title: 'Server Down',
body: 'Production is unreachable',
priority: Priority.high,
deliverAt: now,
));
store.add(Notification(
title: 'Welcome',
body: 'Thanks for signing up!',
priority: Priority.normal,
deliverAt: now.add(Duration(hours: 1)),
));
// Combine filters with AND semantics — all non-null filters must match.
final urgentMatches = store.search(
query: 'server',
priority: Priority.high,
after: now.subtract(Duration(minutes: 5)),
before: now.add(Duration(minutes: 5)),
);
final inner = MemoryDeliveryBackend();
final logged = LoggingDeliveryBackend(
inner: inner,
sink: (n) => print('[delivering] ${n.id} — ${n.title}'),
);
final manager = NotificationManager(backend: logged);
final manager = NotificationManager(
backend: backend,
onDeliver: (n) => print('Delivered: ${n.title}'),
);
| 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 |
NotificationStore.removeWhere() | Remove all notifications matching a predicate |
NotificationStore.search() | Search notifications by query, priority, channel, and deliverAt date range (AND-combined) |
NotificationTemplate() | Create a reusable template with {{variable}} placeholders |
NotificationTemplate.build() | Build a notification by substituting variables into the template |
NotificationTemplate.placeholders | Extract all placeholder names from the template |
RateLimiter() | Create a per-channel rate limiter with a cooldown duration |
RateLimiter.allow() | Check if a channel is allowed to deliver |
RateLimiter.reset() | Clear cooldown tracking for a channel |
RateLimiter.resetAll() | Clear all cooldown tracking |
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 |
LoggingDeliveryBackend | Decorator that emits each notification to a sink before delegating to an inner backend |
dart pub get
dart analyze --fatal-infos
dart test
If you find this project useful: