Build AccountingExportScreen BLoC and state model
epic-accounting-system-export-ui-task-004 — Create the AccountingExportScreenBloc (BLoC pattern) with states: Idle, LoadingConfig, ConfigLoaded(exporterType, orgName), Exporting, ExportSuccess(exportRunId, fileUrl), ExportError(message), and DuplicateWarning(existingRunId). Events: LoadConfig, InitiateExport(dateRange), ConfirmExport, CancelExport, DownloadFile. BLoC coordinates calls to the Export Edge Function client and Double-Export Guard. Guard-detected duplicates must transition to DuplicateWarning state before proceeding.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Use sealed classes (Dart 3.0+) for both events and states to enable exhaustive pattern matching in the UI. Define a single abstract AccountingExportState base and AccountingExportEvent base. Inject repository dependencies via the BLoC constructor (not via Riverpod inside the BLoC) to keep the BLoC testable without the Riverpod container. The Double-Export Guard should be a separate class (not inlined in BLoC) that accepts a date range and org ID and returns a DuplicateCheckResult.
Implement CancelExport by storing the last-known ConfigLoaded state as a field so it can be re-emitted on cancel without re-fetching. Avoid using BLoC transformers for this use-case — sequential event processing (default) is correct here since export is a sequential operation.
Testing Requirements
Unit tests using bloc_test package: test each event→state transition in isolation with mocked repositories. Specifically test: LoadConfig success path (Idle→LoadingConfig→ConfigLoaded); LoadConfig failure path (Idle→LoadingConfig→ExportError); InitiateExport with duplicate detected (ConfigLoaded→DuplicateWarning); InitiateExport without duplicate (ConfigLoaded→Exporting→ExportSuccess); ConfirmExport override path skips guard; CancelExport from DuplicateWarning returns to ConfigLoaded. Use mocktail or mockito to mock the Export Edge Function client and Double-Export Guard. Verify BLoC emits states in the correct order using blocTest's 'expect' list.
Verify BLoC.close() cancels all stream subscriptions. Target 95%+ coverage on BLoC logic.
Export operations may take several seconds, and the UI must handle all intermediate states (loading, partial success, failure, duplicate warning) without leaving the coordinator on a blank or unresponsive screen. Missing state handling causes confusion and potentially double-submissions.
Mitigation & Contingency
Mitigation: Design the BLoC state machine with explicit states for each transition before writing any widget code: ExportIdle, ExportDuplicateWarning, ExportInProgress, ExportSuccess, ExportPartialSuccess, ExportFailed. Each state maps to a distinct UI. Widget tests cover all states.
Contingency: If a loading state is missed in production, surface a generic error state with a retry action rather than leaving the UI stuck. Add a timeout on the Edge Function call (default 30 seconds) that transitions to ExportFailed with a user-readable message.
The custom Export Date Range Picker may not be fully navigable with VoiceOver if the underlying Flutter date widgets do not expose the correct semantic tree. This is a critical accessibility failure for Blindeforbundet users who rely on screen readers.
Mitigation & Contingency
Mitigation: Use Flutter's built-in DateRangePicker as the base and wrap with explicit Semantics nodes for start and end labels. Test with VoiceOver on a physical iOS device as part of the definition of done for this component. Reference the existing AccessibilityTestHarness pattern used elsewhere in the app.
Contingency: If the custom picker fails accessibility audit, replace it with two independent DatePicker fields (start and end) using Flutter's standard accessible date input, which has broader VoiceOver support than range variants.