diet-guard/app/lib/services/notification_backend.dart
2026-11-09 08:21:06 +01:00

38 lines
1.5 KiB
Dart

/// The platform notification surface behind [NotificationService].
library;
/// Shows and cancels one notification per meal slot.
///
/// Free of any plugin import so [NotificationService]'s due-slot logic
/// compiles for web: the implementations are
/// `notification_backend_io.dart` (`flutter_local_notifications`) and
/// `notification_backend_web.dart` (the browser's Notifications API),
/// selected by the conditional export in
/// `notification_backend_factory.dart`.
abstract class NotificationBackend {
/// Prepares the platform surface. Called once, before any [show]/[cancel].
Future<void> initialize();
/// Asks the platform for permission to post notifications.
///
/// Returns null where the concept does not apply, which callers treat the
/// same as false: notifications degrade silently rather than blocking use
/// of the app.
Future<bool?> requestPermission();
/// Posts (or replaces) the notification for [slot], titled with the slot's
/// clock time and carrying no body text.
Future<void> show(int slot, String title);
/// Removes the notification for [slot], if one is showing.
Future<void> cancel(int slot);
/// Returns the ids of the meal reminders currently showing.
///
/// Must include reminders posted by *earlier* builds and runs (on Android
/// the hour-keyed ids an older version left behind), because this is what
/// lets `NotificationService.syncToSlots` cancel orphans without sweeping
/// every possible id. May throw; the caller then falls back to a sweep.
Future<Set<int>> activeIds();
}