Implement Organisation Field Config Loader
epic-structured-post-session-report-form-engine-task-005 — Create the infrastructure component that fetches and parses org-specific field configuration from Supabase, mapping raw JSON schema to typed FieldConfig domain objects. Support field types: text, textarea, checkbox, radio, select, number, date, and way_forward_section. Integrate with report schema cache for offline support. Expose a Riverpod provider returning AsyncValue<List<FieldConfig>>.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Implement as an AsyncNotifierFamily provider: `final orgFieldConfigProvider = AsyncNotifierProvider.family
Keep the Supabase table query in a dedicated OrgFieldConfigRepository class for testability. The WayForwardSectionConfig is a special case — it acts as a section boundary in the form, not a regular input field; ensure the renderer handles it distinctly.
Testing Requirements
Unit tests (flutter_test): (1) happy path — mock Supabase returning valid JSON for all 8 field types, assert correct FieldConfig variants and sort order, (2) unknown field type 'signature' is skipped, remaining configs returned, (3) malformed row (missing required key) is skipped, (4) network error triggers cache read — mock cache returns stale data, assert AsyncValue.data emitted, (5) network error + empty cache emits AsyncValue.error(OfflineException), (6) empty result set returns AsyncValue.data([]), (7) unauthenticated call throws before Supabase request. Use Riverpod ProviderContainer with overrides for the Supabase client mock. Integration test against a Supabase staging environment: insert 3 field configs for a test org, fetch, assert count and types. Minimum 85% line coverage.
Dynamically rendered form fields built from runtime JSON schema are significantly harder to make accessible than statically declared widgets — Flutter's Semantics tree must be correct for every possible field type and every validation state. Failures here block the entire feature for Blindeforbundet's visually impaired peer mentors.
Mitigation & Contingency
Mitigation: Define WCAG 2.2 AA semantics requirements for each field type before implementation and write widget tests using Flutter's SemanticsController for every type. Include a real-device VoiceOver test session in the acceptance gate for this epic before marking it done.
Contingency: If dynamic semantics prove too difficult to get right generically, implement field-type-specific Semantics wrappers (one per supported field type) instead of a single generic renderer, accepting slightly more code duplication in exchange for reliable accessibility.
The report-form-orchestrator must manage a complex state machine — schema loading, draft persistence, per-field validation, submission retries, and error recovery — across multiple async operations. Incorrect state transitions could result in lost user data, double submissions, or UI freezes.
Mitigation & Contingency
Mitigation: Define all Bloc states and events explicitly as sealed classes before writing any logic. Use a state machine diagram reviewed by the team before implementation. Write exhaustive Bloc unit tests covering every state transition, including concurrent events and network interruption mid-submission.
Contingency: If Bloc complexity becomes unmanageable, extract draft persistence into a separate DraftManagerCubit and keep report-form-orchestrator focused solely on the submit workflow. The additional granularity makes each component independently testable.
Organisations may require field types beyond the five currently specified (text, multiline, checkbox group, radio, date). If a new type is discovered during pilot testing, the dynamic-field-renderer must be extended, potentially requiring changes across multiple layers.
Mitigation & Contingency
Mitigation: Design dynamic-field-renderer as a registry of field-type renderers with a clear extension point. Document the pattern for adding a new field type so that it can be done in one file without touching existing renderers.
Contingency: If an unhandled field type is encountered at runtime, dynamic-field-renderer renders a labelled plain-text fallback widget and logs a warning so the missing type is surfaced in monitoring, preventing a crash while making the gap visible.