Load and display triggering activity context in Detail Sheet
epic-scenario-based-follow-up-prompts-scheduler-and-ui-task-009 — Wire the Detail Bottom Sheet to fetch full activity context from the repository when opened. Display peer mentor name, activity date, duration, notes snippet, and any wellbeing flags set on the activity. Use Riverpod FutureProvider with loading and error states following existing patterns.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 7 - 84 tasks
Can start after Tier 6 completes
Implementation Notes
Create a dedicated ActivityContextProvider using riverpod's FutureProvider.autoDispose.family
Locale-aware date formatting should use intl's DateFormat('dd.MM.yyyy') — confirm the intl package is already a dependency before adding. For the loading state, use a Column of shimmer Container placeholders matching the approximate layout of the loaded state. Follow the existing Riverpod provider naming conventions in the codebase. Do not use .watch inside initState — use ConsumerWidget or ConsumerStatefulWidget pattern.
Testing Requirements
Write widget tests and unit tests using flutter_test. Unit test 1: activityContextProvider returns correct ActivityContext model when repository returns valid data. Unit test 2: Duration formatting helper converts raw minutes to '1 t 30 min' format correctly including edge cases (0 min, 60 min exactly, 90 min). Widget test 1: Sheet shows skeleton widgets when FutureProvider is in loading state.
Widget test 2: Sheet shows correct peer mentor name, date, and duration on success state. Widget test 3: Sheet shows error widget with retry on FutureProvider error state. Widget test 4: Notes section hidden when notes field is null or empty. Widget test 5: Provider auto-disposes when sheet is removed from widget tree (verify with ProviderContainer).
Mock the Activity repository using Mockito or manual stubs — do not call Supabase in widget tests.
If the scheduler runs concurrently (e.g., two overlapping cron invocations due to edge function retry), duplicate prompts could be dispatched before the first run's history records are committed, breaking the deduplication guarantee.
Mitigation & Contingency
Mitigation: Use a Postgres advisory lock or unique constraint on (user_id, scenario_id, activity_ref) in the prompt history table to make concurrent writes idempotent; design the scheduler to check history inside a transaction.
Contingency: If concurrency issues persist in production, add a distributed lock via Supabase Edge Function concurrency limit (max_instances=1) for the evaluation function as a hard guard.
Coordinators may find scenario configuration unclear if trigger conditions are expressed as raw JSON or technical terminology, leading to misconfiguration and irrelevant prompts being sent to peer mentors.
Mitigation & Contingency
Mitigation: Design the ScenarioConfigurationScreen to display human-readable descriptions of each template's trigger condition (e.g., 'Send 3 days after first contact if wellbeing concern was flagged') rather than raw rule properties; validate with an HLF coordinator in a design review before implementation.
Contingency: If coordinators still misconfigure rules after launch, add a preview mode that shows a simulated prompt based on a test activity before the rule is enabled.