Receipt Capture Widget — image_picker integration
epic-travel-expense-registration-ui-task-003 — Build the receipt capture widget using the image_picker package to support camera capture and gallery selection. Display an upload progress indicator while the image is being compressed and transferred to the receipt storage adapter. Show a mandatory-attachment signal (prominent visual indicator + accessible warning) when the current expense amount exceeds the configured threshold from ExpenseThresholdConfig.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Use image_picker 1.x API (ImagePicker().pickImage). Compress via flutter_image_compress or the built-in imageQuality parameter. Run compression in compute() to avoid jank. Implement ReceiptStorageAdapter as an abstract class with a SupabaseReceiptStorageAdapter implementation — this makes unit testing easy with a mock adapter.
The threshold check should be a pure function: bool isReceiptRequired(double amount, ExpenseThresholdConfig config) => amount >= config.receiptRequiredAbove. Dispatch ReceiptAttached/ReceiptRemoved events to ExpenseFormBloc so the BLoC owns the 'receipt required' state rather than the widget. Use StreamController or a BLoC stream for upload progress updates. For iOS, ensure NSCameraUsageDescription and NSPhotoLibraryUsageDescription are set in Info.plist; for Android, READ_EXTERNAL_STORAGE / READ_MEDIA_IMAGES permissions are declared in AndroidManifest.xml.
Testing Requirements
Unit tests: mock image_picker and receipt storage adapter; test compression logic with images of known sizes; test threshold detection for amounts below, at, and above threshold. Widget tests: mock PickedFile response, assert progress indicator appears and disappears; assert mandatory-attachment banner appears when amount > threshold and disappears when amount drops below. Integration test: end-to-end upload to Supabase Storage staging bucket, assert receipt URL is returned and stored in BLoC state. Permission-denial path: mock permission denial, assert inline fallback message is displayed.
Target ≥ 85% line coverage on capture and upload logic.
The image_picker Flutter plugin requires platform-specific permissions (NSPhotoLibraryUsageDescription, camera permission) and behaves differently across iOS and Android versions. Permission denial or plugin misconfiguration can silently prevent receipt attachment.
Mitigation & Contingency
Mitigation: Configure all required permission strings in Info.plist and AndroidManifest.xml during initial plugin setup. Use the permission_handler package to check and request permissions before launching the picker, with clear user-facing explanations. Test on both platforms across at least two OS versions.
Contingency: If image_picker proves unreliable on a specific platform version, fall back to file_picker as an alternative that uses the OS document picker interface, which requires fewer permissions on some Android versions.
The expense form BLoC manages interconnected state across expense type selection, field visibility, receipt requirement, threshold evaluation, and submission flow. Incorrect state transitions can cause UI inconsistencies such as required receipt indicator not updating after amount change, or form appearing valid when mutual exclusion is violated.
Mitigation & Contingency
Mitigation: Model BLoC states as sealed classes with exhaustive pattern matching. Write state transition unit tests covering every combination of: type selection change, amount field change above/below threshold, receipt attachment/removal, and offline mode toggle. Use bloc_test for comprehensive state sequence assertions.
Contingency: If BLoC complexity becomes unmanageable, split into two BLoCs — one for type selection/exclusion state and one for field values/submission — coordinating via a parent provider, accepting the small overhead of inter-BLoC communication.
The expense type selector must enforce mutual exclusion visually by disabling options and showing conflict tooltips, while remaining fully accessible to screen reader users who cannot perceive visual disable states. Incorrect semantics labelling will fail WCAG 2.2 AA requirements critical for Blindeforbundet and HLF users.
Mitigation & Contingency
Mitigation: Use Flutter Semantics widgets to explicitly set disabled state and provide conflict explanations as semanticLabel strings on disabled options. Run accessibility audits with TalkBack and VoiceOver during widget development, not post-completion. Reference the project's accessibility test harness for required test coverage.
Contingency: If custom widget accessibility is difficult to certify, implement the selector as a standard Flutter Radio/Checkbox group with built-in accessibility semantics and an explanatory Text widget below each conflicting option, sacrificing visual elegance for guaranteed WCAG compliance.