diet-guard/app/lib/services/notification_backend.dart
Krzysztof kuhy Rudnicki f83938bfe3 app: minute-of-day slots (phase 2 of 3: every app consumer)
- FoodEntry.slot -> slotMinute: read via entrySlotMinute, written via
  slotFields (whole-hour stays byte-identical, else slot_min), kept by
  copyWithDeleted and the edit screen, so the phone never republishes a
  stripped copy of a PC entry. Out-of-range peer values echo, never throw.
- Satisfaction is nearest-slot snapping (satisfiedSlots) everywhere:
  loggedSlotsToday, due check, kuchnia occupancy, future-day logged set
  (that day's schedule), slot selector. Schedule edits no longer un-log.
- Future pre-log builds DateTime from slot ~/ 60, slot % 60.
- Schedule history + sync go through scheduleToWire/scheduleFromWire.
- Notifications: ids are slot minutes; syncToSlots cancels whatever the
  platform reports active (getActiveNotifications, reminder channel) that
  is not due, covering legacy hour ids; full 0..1439 sweep only if the
  lookup throws.
- Settings: 15-minute dropdowns + "Custom..." (24h showTimePicker), off-grid
  values always selectable, counts capped by grid capacity; editor moved
  to widgets/meal_schedule_editor.dart + meal_time_dropdown.dart.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015npsYVB2PdtWkG7MPAi4tn
2026-10-10 19:55:26 +02:00

37 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].
Future<void> show(int slot, String title, String body);
/// 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();
}