Build Duplicate Warning Bottom Sheet
epic-duplicate-activity-detection-state-management-task-008 — Implement the DuplicateWarningBottomSheet Flutter widget that intercepts the activity wizard save action and presents the duplicate candidate with action buttons (Proceed Anyway, Cancel, View Details). Uses DuplicateComparisonPanel for detail view. Must support screen readers, cognitive accessibility guidelines, and plain-language error messaging per NHF requirements.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Use showModalBottomSheet with isDismissible: false and enableDrag: false to prevent accidental closure. Wrap the sheet content in a DraggableScrollableSheet only if you need variable height — for this use case a fixed-height StatefulWidget is simpler and avoids accidental drag-dismiss. Read font_scale_factor from accessibility_preferences via a Riverpod provider and apply as a MediaQuery override scoped to the sheet, not globally. Use the BLoC's DuplicateWarningState to drive the loading state on the 'Proceed Anyway' button — never manage loading state locally in the widget.
For the expandable comparison panel, use AnimatedSize around the DuplicateComparisonPanel with a Curve.easeInOut animation. Ensure the Semantics tree announces the warning on sheet open by using a post-frame SemanticsService.announce() call. Follow NHF's cognitive accessibility requirement: keep warning text to maximum 2 sentences, use active voice, and avoid double negatives.
Testing Requirements
Widget tests: verify sheet cannot be dismissed via drag or back button. Verify all three action buttons are present and have correct Semantics labels. Verify loading state disables 'Proceed Anyway' button. Verify DuplicateComparisonPanel is hidden initially and expands on 'View Details' tap.
Verify plain-language warning text is present. Accessibility tests: use flutter_test's SemanticsController to verify focus order and screen reader announcements. Test at font scale 2.0 that no text overflows its container. Golden tests: screenshot at font scales 1.0 and 2.0 to catch layout regressions.
BLoC integration test: verify correct BLoC events are emitted on each button tap.
For bulk registration with many participants, running duplicate checks sequentially before surfacing the consolidated summary could introduce a multi-second delay as each peer mentor is checked individually against the RPC. This degrades the bulk submission UX significantly.
Mitigation & Contingency
Mitigation: Issue all duplicate check RPC calls concurrently using Dart's `Future.wait` or a bounded parallel executor (max 5 concurrent calls to avoid Supabase rate limits). The BLoC collects all results and emits a single BulkDuplicateSummary state with the consolidated list.
Contingency: If concurrent RPC calls hit Supabase connection limits or rate limits, implement a batched sequential approach with a progress indicator showing 'Checking participant N of M' so the coordinator understands the delay is expected and bounded.
In proxy registration, the peer mentor's ID must be used as the duplicate check parameter, not the coordinator's ID. If the proxy context is not correctly threaded through the BLoC and service layer, duplicate checks will silently run against the wrong person, missing actual duplicates.
Mitigation & Contingency
Mitigation: Define a `SubmissionContext` model that carries the effective `peer_mentor_id` (distinct from `submitter_id`) and pass it explicitly through the BLoC event payload. The DuplicateDetectionService always reads peer_mentor_id from SubmissionContext, never from the authenticated user session.
Contingency: If SubmissionContext threading proves difficult to retrofit into the existing proxy registration BLoC, add an assertion in DuplicateDetectionService that throws a descriptive error when peer_mentor_id is null or matches the coordinator's own ID in a proxy context, making the bug immediately visible in testing.