zakariaf/flutter-skills/local-notifications-scheduler
Claude Code and agent skill by zakariaf/flutter-skills
- community
Checking that the SKILL.md file is still in the repository.
Enforces an on-device reminder engine where the local database is the only source of truth and the OS pending-notification set is a disposable cache reconciled through one idempotent syncNotifications() entrypoint; keeps flutter_local_notifications behind a single NotificationGateway port, all scheduling math pure and Clock-injected, recurring schedules stored as wall-clock + recurrence rule (never UTC instants) and resolved to a TZDateTime in tz.local for DST correctness, inexact-alarm default with SCHEDULE_EXACT_ALARM as an opt-in, iOS ~64-cap budgeting, isolate-safe @pragma('vm:entry-point') tap handlers, and Android boot re-arm. Use when writing or editing notification_gateway.dart, fln_notification_gateway.dart, reminder_scheduler.dart, recurrence_rule.dart, syncNotifications, zonedSchedule wiring, snooze or mark-done re-anchoring, or diagnosing missed or wrong-hour notifications.
Install
npx vskill@latest install zakariaf/flutter-skills/local-notifications-schedulerSKILL.md
The same SKILL.md was published earlier as zakariaf/flutter-skills/local-notifications-scheduler.
Local Notifications Scheduler
One on-device reminder engine, owned centrally, with a narrow API. The local DB is the source of truth; the OS pending set is a disposable cache. Every scheduling change flows through one pure-then-reconcile path so the whole engine is verifiable off-device. Applies whenever you schedule, cancel, or reason about local notifications.
Read the reference for the task at hand:
references/notification-gateway-port.md— the port contract, the two adapters, channels/grouping/deep-link payload rules.references/scheduler-and-recurrence-rules.md— pureReminderScheduler.computediff, recurrence/DST math, deterministic IDs, budgeting, the full test matrix.references/platform-boot-exact-alarms-oem.md— boot re-arm, exact-alarm degradation, background-isolate safety, Android manifest/Gradle, the OEM survival matrix.
Run scripts/check-single-fln-import.sh, scripts/check-scheduler-purity.sh, scripts/check-adhoc-schedule-calls.sh, and scripts/check-manifest-permissions.sh before a PR.
Non-negotiable rules
- The local DB is the ONLY source of truth. The OS pending-notification set is a disposable cache you reconcile against — never the store of record. Every reminder must be reconstructible from the DB alone after process death, reboot, Doze, or restore.
- Route EVERY scheduling change through one `syncNotifications()` reconcile entrypoint. Never call
gateway.schedule()/cancel()ad hoc from feature or UI code — that path cannot be made idempotent and desyncs the cache. - Import `flutter_local_notifications` in exactly one file — the FLN adapter. Everything else, including all tests, talks to the
NotificationGatewayport. A grep gate fails the build on any other import. - Keep all scheduling math in pure, side-effect-free classes. No plugin calls, no IO, no
DateTime.now()inside them — inject aClockfrompackage:clock: Riverpod code reads it fromclockProvider, the pure math takes it as a parameter (neverDateTime.now(), never a bespokeClockService). Purity is what makes off-device unit testing viaFakeNotificationGatewaypossible. - Store recurring schedules as wall-clock + recurrence rule, resolve to `TZDateTime` only at schedule time. Never persist a recurring schedule as a UTC instant — it drifts an hour across every DST boundary. True one-off instants stay UTC epoch millis.
- Set `tz.local` at startup (from
flutter_timezone). Thetimezonepackage defaults to UTC — forget this and everyzonedSchedulefires at the wrong local hour. - Default to `AndroidScheduleMode.inexactAllowWhileIdle` (permission-free, pierces Doze). Gate exact firing behind the user-revocable
SCHEDULE_EXACT_ALARMviacanScheduleExactAlarms()with silent fallback to inexact. Never declareUSE_EXACT_ALARM— Play policy restricts it to alarm/timer/calendar apps and risks store rejection. - Budget to ~50 pending on iOS (headroom under the silent 64-cap). Sort future instants ascending, take the nearest ~50, refill on every foreground. The 65th+ silently never fires, with no error.
- Use deterministic IDs derived from
reminderId + occurrenceIndexplus a hash of the resolved fire instant and notification content.getPending()exposes only theid, notwhen— so if the id ignored the fire time, editing a reminder without changing its occurrence (a one-off moved 09:00→14:00, or a daily rule's hour changed) would keep the same id, be skipped by BOTH the cancel and schedule loops, and fire at the OLD time. Folding the resolvedTZDateTime(and content) into the id makes an edit produce a NEW id — old id cancelled, new id scheduled. Unchanged input still maps to the same id, so reconcile stays a no-op. - The app-foreground reconcile is the reliability backbone. Boot receiver, background ticks, exact-alarm toggle, and OEM survival are all explicitly best-effort. With no server push there is no way to learn a reminder was dropped except the next foreground reconcile diff — that constraint is why this architecture exists, not a gap to paper over.
Package / folder layout
The engine is shared infrastructure, not a feature — the pure math lives in core/ (no Flutter, off-device testable) and the side-effect port + live impl + reconcile live in services/. project-structure-and-packages owns this tree.
When multi-package (workspace): promote the pure math + gateway into apackages/notificationspackage (wherelib/src/+ one public barrel is the sanctioned convention) so the ~N features that feed it cannot diverge. In a single-package app thecore/+services/split is enough. Seeproject-structure-and-packages.
Wire construction through Riverpod providers — never global singletons or per-feature instances. The Clock comes from clockProvider (Clock.fixed(...) in tests); see service-boundary-and-native for the throws-until-overridden port provider pattern.
The canonical reconcile (the backbone)
compute is pure; the gateway diff is the only IO. This is the ONE entrypoint every scheduling change flows through.
Call syncNotifications() on: app foreground/resume, reminder CRUD, backup import/restore, exact-alarm permission granted, Android boot, and the daily background tick. See examples/sync_notifications.dart for the annotated version including the after-restore path.
The gateway port
The port isolates the plugin so all scheduling math and all tests stay off-device.
Keep it to exactly these four operations — anything more is a signal the logic belongs in the pure ReminderScheduler. The concrete FlnNotificationGateway is the single file importing flutter_local_notifications, timezone, and flutter_timezone; the FakeNotificationGateway is an in-memory List. Wire the concrete one through a Riverpod provider that tests override with the fake in a ProviderContainer. Full contract and the ScheduledNotification value object: references/notification-gateway-port.md and examples/notification_gateway.dart.
Recurrence & DST
Resolve wall-clock + rule to a TZDateTime in tz.local at schedule time — DST-correct by construction.
Genuinely calendar-recurring items may use one repeating notification (matchDateTimeComponents) consuming a single slot; everything else is a one-shot recomputed each reconcile. Mark-done re-anchoring: compute the next occurrence from the actual completion time, not the scheduled one, so recurring reminders don't drift. Never store "9am" as a UTC instant.
Some apps derive a reminder time from a non-time trigger (e.g. "remind after N completions"). Keep that projection in a pure, Clock-injected helper that resolves to a concrete future instant before it reaches the scheduler, so the scheduler still handles one homogeneous list of instants. Debounce re-projection so a stream of inputs doesn't cause a reschedule storm.
Background isolate & tap handling
The background tap/action handler needs @pragma('vm:entry-point') and runs in a separate isolate with no main-isolate state. Do not write to the DB from it — record a lightweight "pending action" intent (or nothing) and let the next foreground reconcile do the real work, avoiding concurrent DB access from two isolates. A tap maps a serializable payload → a go_router location reconstructed from the DB — never a non-serializable extra. See async-safety for mounted/context guards after the await, and references/platform-boot-exact-alarms-oem.md.
Localization & backup
Notification titles/bodies are localized through gen-l10n with ICU plurals and numeral normalization; the schedule instant stays a Gregorian TZDateTime regardless of display calendar (see i18n-rtl-l10n). Backup does not carry OS notification state or exact-alarm grants — after import, run cancelAll() then a full reconcile; never assume restored pending IDs are valid.
Anti-patterns
- Calling `gateway.schedule()` from a feature/ViewModel. Desyncs the cache and can't be made idempotent. Route through
syncNotifications(). - Persisting a recurring schedule as a UTC instant. Shifts the fire time by an hour across every DST boundary. Store wall-clock + rule.
- `DateTime.now()` inside the scheduler. Kills off-device testability. Inject a
Clock. - Declaring `USE_EXACT_ALARM` to "just make it fire on time." Play-policy rejection risk. Use the
SCHEDULE_EXACT_ALARMopt-in with inexact fallback. - Scheduling an unbounded set. iOS silently drops past 64. Budget and refill.
- Writing to the DB from the tap isolate. Concurrent access risks corruption. Record intent; reconcile on foreground.
- Trusting a green emulator run for reboot/Doze/OEM survival. Emulators lie. That confidence comes only from the real-device matrix.
- Treating the OS pending set as the store of record. It's a cache. The DB is truth.
Definition of done
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/local-notifications-scheduler/SKILL.md
Popularity
- Repository stars
- 22
- Repository forks
- 4
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zakariaf/flutter-skills/local-notifications-scheduler)