Add Filter Change Event Handling to StatsBloc
epic-coordinator-statistics-dashboard-core-logic-task-011 — Wire StatsBloc FilterChanged event to update the active StatsFilter (period preset: 30d / 90d / 12m / custom date range) and trigger a debounced reload via CoordinatorStatsService. The period filter must also propagate to PersonalStatsBloC for the personal stats view within the same screen. Ensure filter state survives screen rebuilds via BlocProvider placement above the route.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
StatsFilter should be a @immutable value class with a copyWith method. Implement preset-to-DateTimeRange resolution as a getter on StatsFilter (e.g. StatsFilter.resolvedRange) so the date math is computed once. For cross-BLoC filter propagation, inject PersonalStatsBloC into StatsBloc constructor: `StatsBloc({required CoordinatorStatsService service, required PersonalStatsBloC personalStatsBloc})`.
This is simpler and more testable than using an EventBus or shared Riverpod provider. For BlocProvider placement: in GoRouter, use the `builder` parameter at the route level to wrap the screen with BlocProvider. Do not use `MultiBlocProvider` inside the screen's build method — that recreates the BLoC on every rebuild. Debounce implementation: `on
The 300ms debounce covers the date picker scrolling UX pattern common in Flutter mobile apps.
Testing Requirements
Unit tests using flutter_test + bloc_test + mocktail. Test cases: (1) FilterChanged with last30d preset → correct DateTimeRange computed and passed to service, (2) FilterChanged with custom range → service called with exact custom dates, (3) two FilterChanged events within 300ms → only one service call made, (4) invalid custom range (start after end) → StatsError emitted with descriptive message, (5) custom range exceeding 366 days → StatsError emitted, (6) FilterChanged propagates to mocked PersonalStatsBloC (verify PersonalStatsFilterChanged added), (7) filter preset maps to correct date arithmetic (last30d = 30 days inclusive), (8) active filter echoed on StatsLoaded state. Widget test: verify BlocProvider placed above route preserves BLoC instance across Navigator.push/pop.
fl_chart's default colour palette may not meet WCAG 2.2 AA contrast requirements when rendered on the app's dark or light backgrounds. If segment colours are insufficient, the donut chart will fail accessibility audits, which is a compliance blocker for all three organisations.
Mitigation & Contingency
Mitigation: Define all chart colours in the design token system with pre-validated contrast ratios. Run the contrast-ratio-validator against every chart colour during the adapter's unit tests. Use the contrast-safe-color-palette as the source palette.
Contingency: If a colour fails validation, replace with the nearest compliant token. If activity types exceed the available token set, implement a deterministic hashing algorithm that maps activity type IDs to compliant colours.
StatsBloc subscribing to the activity registration stream creates a long-lived subscription. If the subscription is not disposed correctly when the dashboard is closed, it will cause a stream leak and potentially trigger re-fetches on a disposed BLoC, resulting in uncaught errors in production.
Mitigation & Contingency
Mitigation: Implement subscription disposal in the BLoC's close() override. Write a widget test that navigates away from the dashboard and asserts no BLoC events are emitted after disposal.
Contingency: If leaks are detected in QA, add a mounted check guard before emitting states from async callbacks, and audit all other BLoC stream subscriptions in the codebase for the same pattern.
PersonalStatsService's Phase 4 gamification data structure is designed against an assumed future schema. If the Phase 4 Spotify Wrapped feature defines a different data contract when it is developed, the structure built now will require a breaking change and migration.
Mitigation & Contingency
Mitigation: Document the contribution data structure with explicit field semantics and versioning comments. Keep the Phase 4 fields as optional/nullable so they do not break existing consumers if the schema evolves.
Contingency: If the Phase 4 schema diverges significantly, the personal stats data can be re-mapped in a thin adapter layer without changing PersonalStatsService's core implementation.