Implement Contact Detail Service
epic-contact-detail-and-edit-main-screen-task-007 — Build the contact detail service that orchestrates data retrieval from contact-detail-repository and assignment-repository, assembles a unified ContactDetailViewModel, resolves org-specific field visibility rules, and exposes a Riverpod AsyncNotifier. Handles loading, error, and empty states. Provides a 500ms load time target by prefetching on route push.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Implement as a Riverpod AsyncNotifierProvider.family
For prefetch on route push, use GoRouter's redirect or a route observer to call the notifier's prefetch method; alternatively, use Riverpod's ref.listen in the router configuration. Keep the ViewModel assembly in a private _buildViewModel() method for readability and independent testability.
Testing Requirements
Unit tests using flutter_test with mocked repository interfaces. Test cases: both repositories return successfully — verify ContactDetailViewModel assembled correctly, repository fetch runs in parallel (verify Future.wait used, not sequential await), contact-detail-repository fails — verify AsyncError emitted with correct failure type, assignment-repository fails — verify graceful degradation (contact data shown without assignment info, not total failure), contact not found — verify ContactNotFoundFailure distinguishable from NetworkFailure, NHF org context — verify chapter_affiliations included in ViewModel, Blindeforbundet context — verify sensitive_field_identifiers included. Cache test: two calls within 30s use same data (mock repository called only once). Target 90%+ 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.