Implement PeerMentorProfileHeader avatar widget
epic-peer-mentor-detail-screen-ui-components-task-007 — Build PeerMentorProfileHeader with a circular avatar that loads from a remote URL and falls back to generated initials in a colored circle when the image is null or fails to load. Include the mentor's display name, org role label (sourced from OrgLabelsProvider), and primary status badge slot. Apply error-state styling (e.g., red border ring) when the mentor's HLF cert is expired.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Create PeerMentorProfileHeader as a StatelessWidget accepting: String? avatarUrl, String displayName, bool hlfCertExpired, Widget? statusBadge, and a BuildContext-based org label resolution. For the initials color, implement a deterministic hash: take displayName.hashCode, take its absolute value, and index into a fixed list of design-token-approved background colors (avoid red/green to not conflict with status semantics).
For the avatar, use a Stack: bottom layer is the initials circle, top layer is the network image (which becomes invisible on error). This avoids a flicker from showing initials then switching to image â instead the image sits on top and the initials are always rendered beneath. For the red ring, wrap the avatar stack in a Container with BoxDecoration(shape: BoxShape.circle, border: Border.all(color: tokenColorError, width: 2.0)) conditionally. The status badge slot should be: if (statusBadge != null) statusBadge else const SizedBox.shrink().
Source org role label via context.read
Testing Requirements
Write widget tests using flutter_test. Test 1: pass a null avatarUrl â assert initials text is displayed and no Image widget is in the tree. Test 2: simulate image load error via a fake network image provider â assert fallback initials appear. Test 3: pass hlfCertExpired: true â assert a Container/DecoratedBox with a red border is present in the widget tree.
Test 4: pass hlfCertExpired: false â assert no red border container exists. Test 5: verify OrgLabelsProvider returns the correct role label by injecting a mock provider. Test 6: pass a null status badge â assert the badge slot renders with zero height. Golden tests are optional but recommended for the avatar + initials fallback for visual regression.
The org labels system may not yet have label keys defined for peer mentor detail screen terminology (role labels, section headings), requiring additions to the label key registry that must be coordinated with the admin configuration team.
Mitigation & Contingency
Mitigation: Audit existing label keys in the terminology system before starting OrgLabelsProvider integration. Submit required new label keys for admin configuration in parallel with component implementation.
Contingency: If label keys are not available at integration time, use hardcoded English fallbacks with a clear TODO for admin configuration, ensuring the widget renders correctly while keys are being provisioned.
The design token semantic colors (warning, error surface) may not meet WCAG 2.2 AA 4.5:1 contrast ratio when rendered on the app's background surface tokens, requiring design system changes that affect the entire app.
Mitigation & Contingency
Mitigation: Run contrast ratio validation on the token palette during Epic 1 design token implementation. Flag any failing pairs to the design system owner before building UI components that depend on them.
Contingency: If tokens fail contrast requirements, define supplementary high-contrast override tokens specific to alert and badge contexts that meet AA without modifying the global palette.