Service Layer medium complexity mobile
3
Dependencies
0
Dependents
3
Entities
0
Integrations

Description

BLoC state management layer for the annual summary screen. Manages loading, period selection, slide state, and share flow events. Coordinates between the UI and service layer, ensuring offline fallback is triggered when the network is unavailable.

Feature: Annual Impact Summary (Wrapped)

wrapped-summary-bloc

Summaries

The Wrapped Summary BLoC is the intelligence layer that ensures peer mentors always see their annual impact story, whether they are online or offline, switching between time periods, or sharing a slide with one tap. By managing all screen state in one coordinated component, the platform delivers a seamless, responsive experience that reflects the quality and reliability users expect from a professional tool. The offline fallback capability is particularly valuable for mentors in low-connectivity environments — ensuring no mentor is locked out of their own achievement data due to network conditions. This reliability directly supports mentor satisfaction and trust in the platform, which is a key driver of mentor retention and the sustained supply of mentoring capacity that the business depends upon.

The Wrapped Summary BLoC has medium complexity and sits at the integration boundary between the UI and three backend services — annual-stats-aggregation-service, summary-share-service, and summary-offline-cache — making it a coordination risk point. It should be implemented after its service dependencies are at least partially stable, with mock implementations used during early development. The event model (LoadSummary, ChangePeriod, ShareSlide, NavigateSlide) should be agreed with the UI team before implementation to avoid interface churn. State emissions (loading, loaded, error, offline) drive all UI transitions, so state completeness must be validated during QA.

The offline state path requires specific test scenarios where network availability changes mid-session. Regression coverage should include period switching while a load is in progress, and share failure handling to ensure the UI receives an actionable error state.

The Wrapped Summary BLoC follows the flutter_bloc pattern: it extends Bloc, registers event handlers in the constructor, and emits typed states to the UI stream. The LoadSummary handler should first check the offline cache via summary-offline-cache, emit an OfflineState with cached data if the network is unavailable, and otherwise delegate to annual-stats-aggregation-service. The ChangePeriod handler should cancel any in-flight load and re-trigger LoadSummary for the new period. The ShareSlide handler delegates to summary-share-service and emits a ShareSuccessState or ShareErrorState based on the result.

Use a Completer or CancelableOperation if the aggregation service call must be cancellable mid-flight. The close() override must cancel subscriptions and in-flight futures to prevent state emissions after the BLoC is disposed. Consider using an equatable-based state hierarchy for efficient state comparison and to prevent redundant UI rebuilds.

Responsibilities

  • Handle LoadSummary, ChangePeriod, ShareSlide, and NavigateSlide events
  • Emit loading, loaded, error, and offline states to the UI
  • Cache last-loaded summary state for offline display
  • Coordinate with the aggregation and share services

Interfaces

add(WrappedEvent event): void
stream: Stream<WrappedState>
loadSummary(mentorId: String, period: SummaryPeriod): void
changePeriod(period: SummaryPeriod): void
shareCurrentSlide(slideIndex: int, channel: ShareChannel): void
close(): Future<void>

API Contract

View full contract →
REST /api/v1/wrapped-summaries 5 endpoints
GET /api/v1/wrapped-summaries
GET /api/v1/wrapped-summaries/:mentor_id
POST /api/v1/wrapped-summaries
PUT /api/v1/wrapped-summaries/:mentor_id
DELETE /api/v1/wrapped-summaries/:mentor_id