Request: Fix Notification Permissions Flow
Source Input
User reported: "we have implemented notifications partially however there is no consent logic, no permissions asked, no smart logic to open the settings to change the permissions - turning it on and off just does something I'm not sure. I'm not able to test this properly in any case."
Current Understanding
Based on codebase analysis:
What EXISTS:
PushNotificationHandler with requestPermission() and hasPermission() methods
NotificationPreferencesService for Firestore-based preference toggles
NotificationSettingsView with UI toggles for global/shopping/cleaning
- FCM token management in
FcmTokenService
- Cloud Functions for sending notifications
What's MISSING/BROKEN:
- The toggles in settings only update Firestore preferences, they DON'T request OS permissions
- No connection between
PushNotificationHandler.requestPermission() and the settings UI
- No consent flow on first app launch or first notification settings visit
- No detection of OS permission state (denied/granted/not-determined)
- No "open system settings" deep link when permission is denied
- Unclear UX when toggling - user doesn't know if OS permissions are granted
The Gap:
- App toggles ≠ OS permissions
- User can enable toggle but if OS permission denied, no notifications arrive
- No way to know current OS permission state in UI
- No guidance to open Settings app when permission denied
Decisions
- Permission Request Trigger: Show a CTA banner on the Home screen when OS permission status is "not determined"
- Permission Package: Use the
permission_handler package to check/request notification permission status
- Banner Visibility: Show banner ONLY when permission is "not determined" (never asked)
- Banner Tap Action: Show a consent bottom sheet with artwork, Cancel (outline) and Accept (primary) buttons stacked vertically
- Accept Action: Request OS permission immediately when Accept is tapped
- Post-Consent (Granted): Show success toast, close sheet, hide banner
- Post-Consent (Denied): Show denied toast, close sheet
- Settings Toggle Sync: Toggle is disabled when OS permission denied, shows info text with "Open Settings" button
- Firestore Sync Logic: Add a nullable
osPermissionGranted field to NotificationPreferencesDto:
null = undetermined (user never made a choice)
true = user granted permission at some point
false = user denied permission at some point
- On app start, if
osPermissionGranted != null AND actual OS permission differs from Firestore globalEnabled, update Firestore to match OS state
- Analytics: Full funnel tracking (banner shown, banner tapped, sheet shown, accepted/cancelled, granted/denied)
Final Intent
Home Screen CTA Banner
- Add a promotional banner/widget on the Home view
- Copy: "Enable notifications to know when your roomies go shopping"
- Visible ONLY when OS permission status is "not determined"
- Tapping opens a consent bottom sheet
Consent Bottom Sheet
- Contains attractive artwork/illustration
- Two buttons stacked vertically:
- Accept (primary, bottom)
- Cancel (outline, above Accept)
- Accept triggers OS permission request
- Cancel dismisses sheet (banner remains visible)
After Permission Request
- Granted: Success toast, sheet closes, banner hides automatically
- Denied: Denied toast, sheet closes
Notification Settings View Changes
- Main "Enable Notifications" toggle syncs with OS permission state
- When OS permission is DENIED:
- Toggle is disabled (cannot interact)
- Show info text explaining permission is needed
- Show "Open Settings" button that deep-links to iOS/Android Settings app
- When OS permission is GRANTED:
- Toggle reflects Firestore
globalEnabled state
- Toggle updates Firestore when changed
- Category toggles work as they do now
Firestore Preferences Sync
- Add
osPermissionGranted: bool? field to NotificationPreferencesDto
- On app startup (after authentication):
- Check if
osPermissionGranted != null (user made a choice before)
- Get actual OS permission status
- If
globalEnabled differs from actual OS permission status, update globalEnabled in Firestore
- When user grants/denies permission:
- Update
osPermissionGranted to true/false
- Update
globalEnabled accordingly
Analytics Events
notification_banner_shown - Banner displayed on home
notification_banner_tapped - User tapped the banner
notification_consent_sheet_shown - Bottom sheet displayed
notification_consent_accepted - Accept button tapped
notification_consent_cancelled - Cancel button or swipe dismiss
notification_permission_granted - OS permission granted
notification_permission_denied - OS permission denied
Reacties