Implement PeerMentorDetailBLoC event handlers
epic-peer-mentor-detail-screen-bloc-and-assembly-task-005 — Implement the PeerMentorDetailBLoC event-driven state machine using flutter_bloc. On LoadPeerMentorDetail, emit loading state then trigger PeerMentorAggregationService. Map aggregation result to PeerMentorDetailLoaded or PeerMentorDetailPartialError states depending on per-source error presence. Wire RefreshPeerMentorDetail event to re-trigger aggregation for pull-to-refresh support.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Use `bloc_concurrency` package: apply `restartable()` transformer to LoadPeerMentorDetail to cancel in-flight requests on new load, and `droppable()` to RefreshPeerMentorDetail to ignore taps during an active refresh. For refresh-while-loaded, emit a `PeerMentorDetailLoading` state that carries the stale model: `emit(PeerMentorDetailLoading(mentorId: event.mentorId, staleData: currentLoadedState?.data))` — the UI layer uses staleData to keep showing content behind the refresh indicator. Use `on
Testing Requirements
Unit tests (flutter_test + bloc_test): (1) Happy path — blocTest emits [Loading, Loaded] on LoadPeerMentorDetail with successful mock service. (2) Partial error — mock service returns partial model with error map; assert [Loading, PartialError] with correct error map. (3) Fatal error — mock service throws; assert [Loading, Error]. (4) Refresh with existing data — emit Loaded state first, then send RefreshPeerMentorDetail; assert Loading carries previous data, then Loaded.
(5) Concurrent load — send two LoadPeerMentorDetail events with different mentorIds; assert only the second one's Loaded state is emitted (droppable/restart transformer). (6) Close mid-fetch — close BLoC while fetch is in progress; assert no state emitted after close. Minimum 95% line coverage on BLoC file.
The parallel Future.wait aggregation pattern may produce race conditions or incorrect merged state when some repositories resolve significantly faster than others, particularly if the BLoC receives a RefreshDetail event while a prior fetch is still in flight.
Mitigation & Contingency
Mitigation: Implement cancellation token pattern in the aggregation service to abort in-flight fetches on new events. Add BLoC test scenarios for rapid successive refresh events to validate state consistency.
Contingency: If race conditions persist, switch to a sequential-with-timeout fetch strategy for the first release and profile the performance impact before deciding whether parallel fetch optimization is worth the complexity.
Integrating PeerMentorDetailScreenWidget into the existing StatefulShellRoute navigation structure may conflict with the Contacts tab's existing route hierarchy, requiring changes to navigation-route-config that could affect other teams' features.
Mitigation & Contingency
Mitigation: Coordinate with the Contact List and Contact Detail feature teams before adding the new route. Review the existing StatefulShellRoute configuration and confirm the peer mentor detail route can be nested under the Contacts branch without path conflicts.
Contingency: If route conflicts arise, temporarily implement the peer mentor detail as a modal overlay (push route) rather than a shell route child, preserving functionality while the navigation architecture conflict is resolved.
The course enrollment screen that the certification alert banner links to may not yet exist or may be implemented in a separate feature epic, leaving a broken navigation tap for HLF users in the initial release.
Mitigation & Contingency
Mitigation: Check the certification management feature implementation status before finalizing Epic 4 scope. If the enrollment screen is not available, design the tap action to open the HLF course enrollment URL in an external browser as an interim solution.
Contingency: Implement the CTA as a configurable action: if the enrollment route exists in the router, push it; otherwise, launch the configured org-specific enrollment URL via url_launcher, ensuring HLF users can always take action on expired certifications.