Implement SummaryOfflineCache read/write API
epic-annual-impact-summary-foundation-task-004 — Build the SummaryOfflineCache class exposing put(summary), get(mentorId, year), getAll(mentorId), delete(mentorId, year), and clear() methods over the Hive box. Include cache-hit/miss logging, error handling for corrupted entries, and an isCached(mentorId, year) convenience method. This component is the sole abstraction over local persistence for summaries.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Keep SummaryOfflineCache as a plain Dart class (not a ChangeNotifier) — it is a thin synchronous wrapper over the already-opened Hive box. Accept the Box
For the corrupted-entry pattern, wrap the get() body in try/catch (HiveError, TypeError) — delete the bad key and return null. Logging should use the project's existing logger abstraction, not print().
Testing Requirements
Unit tests (flutter_test) with an in-memory Hive box mock or a temporary test directory: (1) put then get returns same object, (2) get on absent key returns null, (3) getAll returns correct subset for a given mentorId when multiple mentors are stored, (4) delete removes entry and subsequent get returns null, (5) delete on absent key does not throw, (6) clear empties box, (7) isCached returns correct boolean, (8) corrupted entry is silently deleted and null returned. Aim for 100% branch coverage on SummaryOfflineCache.
Rive animation files may not be available at implementation time, blocking the wrapped-animation-controller from being fully tested. If asset delivery is delayed, the controller cannot be validated for memory-leak-free disposal.
Mitigation & Contingency
Mitigation: Implement the animation controller with stub/placeholder AnimationController instances first so the lifecycle and disposal logic can be unit-tested independently of Rive assets. Define a named animation registry interface early so UI components can reference animations by name without coupling to specific Rive files.
Contingency: If Rive assets are not delivered before Epic 3 begins, replace Rive animations with Flutter implicit animations (AnimatedOpacity, ScaleTransition) as a drop-in and schedule Rive integration as a follow-on task once assets arrive.
The annual_summaries Supabase RPC aggregating 12 months of activity records per mentor may exceed acceptable query latency (>2s) for mentors with high activity volumes such as the HLF mentor with 380 registrations cited in workshop notes.
Mitigation & Contingency
Mitigation: Design the RPC to materialise summary results into the annual_summaries table via a scheduled edge function rather than computing on demand. The repository reads pre-computed rows, keeping query latency constant regardless of activity volume.
Contingency: If on-demand queries are required for real-time period switching, add a PostgreSQL partial index on (mentor_id, activity_date) and implement a client-side loading skeleton so slow queries degrade gracefully rather than blocking the UI.
iOS requires photo library permission before saving a screenshot to the gallery. If the permission prompt is triggered at an unexpected point in the share flow, the UX breaks and users may deny permission permanently, making gallery save unavailable.
Mitigation & Contingency
Mitigation: Trigger the permission request only when the user explicitly chooses 'Save to gallery' in the share overlay, not on screen load. Implement a pre-prompt explanation screen following Apple HIG so users understand why the permission is needed before the system dialog appears.
Contingency: If permission is denied, gracefully fall back to clipboard copy and system share sheet options which do not require photo library access, and surface a non-blocking snackbar explaining the limitation.