Build Encrypted Field Display Widget
epic-contact-detail-and-edit-main-screen-task-012 — Implement the encrypted field display widget for Blindeforbundet sensitive fields (name, address, epikrise reference). The widget shows a masked placeholder by default, requires an explicit tap-to-reveal interaction, uses field-encryption-utils for decryption on reveal, triggers read-receipt-service on first reveal, and displays a screen reader warning dialog before exposing sensitive content. Must meet WCAG 2.2 AA contrast and focus requirements.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Use a `StatefulWidget` with `WidgetsBindingObserver` to listen for `AppLifecycleState.paused` and call `setState(() => _revealState = RevealState.masked)`. Store `_decryptedValue` as a nullable `String?` and set it to `null` on re-mask. Use a `Semantics` widget with `onTap` override to ensure VoiceOver/TalkBack exposes the tap affordance. The warning dialog must use `showDialog()` with `barrierDismissible: false` so the user must make an explicit choice.
Guard the `recordReceipt` call with a session-level flag (stored in the provider, not the widget) so it fires only once per app session per field identifier. Use `AnimatedSwitcher` for the masked-to-revealed transition to avoid layout jank. The `PreviouslyViewedBadge` should be a small, accessible chip that does not interfere with the tap target of the main widget.
Testing Requirements
Widget tests (flutter_test): (1) verify masked placeholder is shown on initial render; (2) tap widget — verify warning dialog appears before any decryption; (3) cancel dialog — verify field remains masked and no decrypt/receipt call made; (4) confirm dialog — mock decryption success and verify revealed text is shown; (5) mock decryption failure — verify error message shown, no partial data; (6) verify `recordReceipt` called exactly once on first reveal, not on second; (7) verify `watchReceiptStatus` returning `read` shows 'Previously viewed' badge in masked state; (8) simulate `AppLifecycleState.paused` — verify field re-masks. Accessibility: verify Semantics labels in both masked and revealed states. Security: verify decrypted value is not present in widget state after re-mask. Target ≥90% line coverage.
The Peer Mentor Profile tab on the contact detail screen depends on the peer-mentor-detail-screen-widget being delivered by the separate Peer Mentor Detail feature. If that feature is delayed, the navigation affordance will be present but lead to a stub screen, which may confuse coordinators in the TestFlight pilot.
Mitigation & Contingency
Mitigation: Implement the peer mentor tab with a feature flag guard. When the Peer Mentor Detail feature is incomplete, the flag disables the tab. Coordinate delivery timelines with the team responsible for Peer Mentor Detail to align TestFlight releases.
Contingency: If the Peer Mentor Detail feature is significantly delayed, ship the contact detail screen without the peer mentor tab in the first TestFlight build and add it as an incremental update once the dependent screen is ready.
The contact detail screen must adapt its layout significantly based on organisation context: NHF shows affiliation chips, Blindeforbundet shows encrypted fields and assignment status, standard contacts show neither. Managing this conditional rendering without introducing bugs in each variant is complex and increases the risk of organisation-specific regressions.
Mitigation & Contingency
Mitigation: Define a ContactDetailViewModel that resolves all org-specific flags (showEncryptedFields, showAssignmentStatus, showMultiChapterChips) from the organisation config before the widget tree renders. Widget tests must cover all three organisation variants as separate test cases to catch regressions.
Contingency: If conditional rendering logic grows unwieldy, refactor into separate composable section widgets (ProfileHeaderSection, AffiliationSection, EncryptedFieldsSection) that are conditionally included by the parent screen, isolating org-specific logic to individual components.