Implement accessibility settings repository with reactive streams
epic-screen-reader-support-foundation-task-004 — Implement the AccessibilitySettingsRepository backed by SharedPreferences or Hive. Expose a Stream<AccessibilitySettings> for reactive updates, plus synchronous read and async write methods. Ensure settings persist across app restarts and are loaded at startup. Register as a Riverpod StreamProvider.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Use a StreamController
The abstract interface (AccessibilitySettingsRepository) enables test injection via Riverpod overrides. For the Riverpod provider: use StreamProvider
Testing Requirements
Write unit tests using flutter_test with a fake/in-memory implementation of the repository interface: (1) stream emits defaults when storage is empty, (2) updateSettings persists and stream emits new value, (3) multiple rapid updates result in correct final value, (4) readSync returns null before first write and correct value after. Write an integration test using real SharedPreferences (via shared_preferences_platform_interface test helpers) verifying persistence across simulated restart. Minimum 85% branch coverage.
Flutter's SemanticsService behaves differently between iOS (VoiceOver) and Android (TalkBack) in edge cases — e.g., announcement queuing, focus-gain timing, and attribute support. If the facade does not correctly abstract these differences, announcements may be silent or misfired on one platform, causing regression on the other platform to go unnoticed until device testing.
Mitigation & Contingency
Mitigation: Write platform-divergence unit tests early using SemanticsServiceFacade mocks. Validate announcement delivery on a physical iPhone (VoiceOver) and Android device (TalkBack) at the end of each sprint. Document known platform differences in the facade's inline API comments.
Contingency: If a platform difference cannot be abstracted cleanly, expose a platform-specific override path in the facade and implement targeted workarounds per platform, accepting the added complexity in exchange for correct behaviour.
Accessibility preferences stored in local storage may need new fields as higher-tier epics are implemented (e.g., announcement verbosity, sensitive-field guard toggle). Schema changes to an already-persisted store risk data migration failures or silent defaults on existing installs, breaking user preferences.
Mitigation & Contingency
Mitigation: Design the AccessibilitySettingsRepository with a versioned JSON schema from the start, using merge-with-defaults on read so new fields fall back gracefully. Define the full expected field list upfront based on all downstream epic requirements before writing the first record.
Contingency: If migration fails on a live install, fall back to full reset-to-defaults with a one-time in-app notification informing the user that accessibility preferences have been reset and inviting them to reconfigure.