Notifications
Local notification initialization, Account FCM registration, and notification history in Flutter.
Two notification layers
The Flutter template separates:
- Local notifications (
helpers/notification.dart) — initialized for every profile and used to display local/foreground notifications. - FCM/remote push (
helpers/notification_push.dart,bootstrap/account_bootstrap.dart) — Account-only token retrieval, refresh listeners, background handling, and server sync.
The main bootstrap initializes local notifications after the first frame. It does not hold the native splash screen on network/FCM work.
Account push flow
For Account mode, initializeAccountPushNotifications():
- Initializes Firebase and requests permission according to
NotificationConfig. - Retrieves and listens for the FCM token.
- Stores it securely and posts it to
POST /api/v1/app/device-tokenswhen a Sanctum token exists. - Displays foreground FCM messages with
flutter_local_notifications. - Registers a background FCM handler and logs notification-open events.
Configure Firebase options/files for the final Android package and iOS bundle ID. The Laravel admin panel reads storage/app/firebase-auth.json to send FCM messages and persists notification history.
Notification history
Authenticated Account users can load paginated history and use:
GET /api/v1/app/notificationsPUT /api/v1/app/notifications/{id}/readPUT /api/v1/app/notifications/read-allDELETE /api/v1/app/notifications/{id}DELETE /api/v1/app/notificationsGET/PUT /api/v1/app/notifications/preferences
notification_history_provider.dart supports refresh, pagination, optimistic read/delete updates, and limited retry handling.
Guest behavior
Guest mode initializes local notification support but never initializes FCM, requests a device token, syncs notification preferences, or calls notification-history APIs. Notification settings stay in SharedPreferences.
The template does not expose a generic local scheduling helper. Add and test an explicit zonedSchedule/local scheduling path if the Guest app needs reminders; initialization alone is not scheduled-delivery support.
Native setup and testing
- Android: configure Firebase, notification channel/icon, and Android 13+ permission behavior.
- iOS: configure APNs credentials/capabilities through Firebase/EAS and test on a physical device.
- Test foreground, background, terminated, denied-permission, token-refresh, logout, and Guest flows.
Notification-open routing is currently logged/handled by the bootstrap/widget layer; add an allowlisted navigation contract before trusting arbitrary payload links.
Relevant files
helpers/notification.darthelpers/notification_push.dartbootstrap/account_bootstrap.dartservices/fcm_service.dartservices/notification_history_service.dartproviders/notification_history_provider.dartproviders/notification_provider.dart
