show method
Displays a notification. Respects DND and channel preferences.
Implementation
Future<void> show(AppNotification notification) async {
// Check DND.
if (_preferences.isDndActive &&
notification.priority != NotificationPriority.urgent) {
// Still store it, but don't push to stream.
_store(notification);
return;
}
// Check channel.
if (notification.groupKey != null) {
final channel = _preferences.channels[notification.groupKey];
if (channel != null && !channel.enabled) {
_store(notification);
return;
}
}
_store(notification);
_streamController.add(notification);
// Auto-expire.
if (notification.expiresAt != null) {
final delay = notification.expiresAt!.difference(DateTime.now());
if (delay.isNegative) {
notification.dismissed = true;
} else {
Timer(delay, () => dismiss(notification.id));
}
}
}