document_camera_frame 2.6.8
document_camera_frame: ^2.6.8 copied to clipboard
Flutter package for capturing and cropping document images with a customizable camera interface.
2.6.8 #
Fixed #
- Improved frame height cap: Reduced the maximum frame height from 45% to 43% of the screen height, creating better visual spacing between the document frame and action buttons on tall frames (e.g. passport).
- Internal refactor:
maxFrameHeightis now computed once inDocumentCameraLogicand reused, eliminating the repeatedMediaQuerycalculation.
2.6.7 #
Fixed #
-
Camera preview no longer stretches/distorts on mismatched sensors:
_CoverFitCameraPreviewnow computes the cover scale directly fromcontroller.value.previewSize, modellingCameraPreview's internalAspectRatiolayout for both portrait and landscape orientations. The previoussize.aspectRatio × controller.value.aspectRatioformula produced an incorrect scale factor in landscape, causing visible squashing. ([document_camera_preview_layer.dart]) -
Crop rectangle now matches what the user sees:
ImageProcessingService.cropImageToFramewas using a stretch-fit linear formula (imgW × frameW / screenW) that assumed the camera texture filled the screen 1:1 — only valid underBoxFit.fill. It now usescoverScale = max(screenW / imgW, screenH / imgH)to back-project the on-screen frame into image-pixel space, matching the cover-fit preview exactly. ([image_processing_service.dart]) -
Auto-capture alignment fixed after cover-fit preview change:
DocumentDetectionServicewas using letterbox-fit geometry (fittedPreviewHeight,verticalOffset) to map ML Kit bounding boxes to screen coordinates and to place the alignment frame in analysis space. With cover-fit rendering that geometry produces a negative vertical offset, misaligning every detection. Both the frame crop rect (Step 4) and_mapBoundingBoxToScreenRectnow usecoverScalewith symmetrichorizontalClip/verticalClipoffsets. ([document_detection_service.dart]) -
Android EXIF orientation guard in crop math: On some Android devices
img.decodeImagereturns sensor-native (landscape) bytes without applying the EXIF rotation tag. When the decoded image dimensions disagree with the screen orientation,cropImageToFramenow swaps the effective width/height before computingcoverScale, preventing a crop centred on the wrong axis. ([image_processing_service.dart]) -
Crop bounds clamping prevents out-of-bounds crash: Floating-point rounding could cause
cropX + cropWidthto exceedoriginalImage.widthby one pixel, throwing insideimg.copyCrop. Crop dimensions and origin are now clamped after rounding. ([image_processing_service.dart]) -
Review screen no longer distorts captured image:
CapturedImagePreviewwas usingBoxFit.fill, stretching the cropped result to fill its container regardless of aspect ratio. Changed toBoxFit.cover. ([captured_image_preview.dart]) -
onCameraErrornow delivers the actual exception: The callback was typed asVoidCallbackinternally and every call site silently discarded the caught error, always forwarding the hardcoded string'Camera error'. The type is nowvoid Function(Object error)?(aligning the implementation with the existing public API docs) and all seven call sites pass the real exception through — including errors surfaced byDocumentDetectionService. ([document_camera_logic.dart], [document_camera_frame.dart])
Migration #
onCameraErrorsignature — if you passed a no-argument lambda, add the error parameter:// Before (2.6.x) onCameraError: () { /* … */ } // After (2.7.0) onCameraError: (Object error) { /* … */ }
2.6.2 #
Documentation #
- Example & README cleanup: Removed
onDocumentSaved: (_) {}from all example code and README snippets. Every snippet now includes the canonical hint comment explaining thatonDocumentSavedis optional and that navigation is handled automatically.
2.6.1 #
Changed #
onDocumentSavedandonBothSidesSavedare now fully optional: Removed the runtimeassertthat required at least one of these callbacks. You can now use the standardawait Navigator.push<DocumentCaptureData>(...)pattern without supplying any callback at all — the package always pops itself with the result.- Fixed visual flicker on save:
Navigator.pop(resultData)is now called beforeresetCapture()insidehandleSave(). This prevents the live camera feed from briefly flashing back on screen during the pop transition animation.
2.6.0 #
Added #
showScreenTitleinDocumentCameraTitleStyle: New property to show or hide the screen title bar. Defaults totrue(visible). Set tofalseto hide the title entirely without affecting other UI elements.
Changed #
- Screen Title always enabled in full UI mode:
frontSideTitleandbackSideTitleinDocumentCameraTitleStylenow default to a white"Front Side"and"Back Side"text widgets respectively. TheScreenTitleis now always rendered in full UI mode, unless disabled viashowScreenTitle: false. showInstructionTextdefault changed tofalse: The top instruction banner is now hidden by default inDocumentCameraInstructionStyleto reduce UI clutter.showSideIndicatordefault changed tofalse: The side indicator (front/back dots) is now hidden by default inDocumentCameraSideIndicatorStyle._DetectionStatusBannerpositioning: The live detection status text (e.g. "Move closer") is now always anchored directly above the camera frame, regardless of whether the instruction banner or side indicator is visible.
Fixed #
- Typo fix: Renamed
innerCornerBroderRadius→innerCornerBorderRadiusinDocumentCameraFrameStyle. The old name was a typo; this is a breaking rename — update any references in your code. showSideIndicatorwas never respected: Fixed_effectiveShowSideIndicatorto actually checksideIndicatorStyle.showSideIndicator. Previously the flag was declared but ignored.showInstructionTextwas never respected: Fixed_effectiveShowInstructionto actually checkinstructionStyle.showInstructionText. Previously the flag was declared but ignored.camScannermode returned no data:_launchCamScannerwas callingNavigator.maybePop()(no argument) on all completion paths, causingawait Navigator.push(...)to always resolve tonull. Fixed by callingNavigator.pop(result)with the capturedDocumentCaptureDataon every success path. Cancellations (empty scan) still usemaybePop()correctly.- Navigation pattern: The package now follows the Flutter-standard
await Navigator.push<DocumentCaptureData>(...)pattern across all modes.handleSave()and_launchCamScannerboth callNavigator.of(context).pop(resultData)so callers receive the result as a typed Future — identical toshowDatePicker,ImagePicker, and other Flutter APIs.onDocumentSavedremains available as an optional side-channel callback.
Migration Guide #
- Rename any usage of
innerCornerBroderRadius→innerCornerBorderRadiusin yourDocumentCameraFrameStyle. - If you relied on
showInstructionTextorshowSideIndicatorbeingtrueby default, pass them explicitly:showInstructionText: true/showSideIndicator: true.
2.5.6 #
- Bug Fix: Removed export of
context_extensions.dartfrom the package export file to prevent conflicts with other packages likeflutter_screenutilthat provide similar BuildContext and double extensions like.sw()and.sh(). Explicit internal imports were added where needed.
2.5.5 #
- Demo Update: Replaced old example GIFs in README with four new demo recordings added in this version — showcasing the default UI mode, export formats, all built-in UI modes, and the native CamScanner mode.
2.5.4 #
- Score Fix: Fixed Swift Package Manager path — moved
Package.swiftto the correct locationios/document_camera_frame/Package.swiftas required by thepanaanalyzer.
2.5.3 #
- Score Fix: Added Swift Package Manager (SPM) support for iOS to achieve full 160/160 pub points.
- Maintenance: Synced podspec and package metadata.
2.5.2 #
- Score Fix: Restored 160/160 pub points by properly registering the Android platform implementation.
- Dependency Update: Bumped
cameradependency to^0.12.0for latest platform supports. - Platform support: Enhanced Android native registration structure for better compatibility with
panaanalyzer.
2.5.0 2.5.1 #
Added #
DocumentCameraUIMode.camScanner: Integrated a new mode that delegates scanning to platform-native engines for professional-grade results.- Android: Leverages Google ML Kit for automatic edge detection, perspective correction, and image filters.
- iOS: Leverages Apple's VisionKit (
VNDocumentCameraViewController) for a high-performance system-native experience.
- Smart Sequential Flow: Native mode now supports automated multi-side scanning. It guides the user through "Front Side" and "Back Side" sessions sequentially with built-in loading scaffolds.
- Last-Capture Selection: Both Android and iOS native modes now automatically favor the final (best) capture from a scanning session when
requireBothSidesis enabled. CamScannerService: Exposed the underlying platform service, allowing developers to trigger native scans programmatically without the full framing UI.
Changed #
- Pubspec Update: Updated dependencies to ensure compatibility with the latest ML Kit and VisionKit APIs.
- Platform Support: Explicitly registered Android platform support in
pubspec.yamland added minimal native Android project structure to ensure correct platform detection on pub.dev.
2.4.0 #
Added #
DocumentCameraUIModeenum — support for five distinct UI modes:defaultMode,minimal,overlay,kiosk, andtextExtract.uiModeparameter onDocumentCameraFrame(fully backward compatible).- Comprehensive UI Mode Matrix:
defaultMode: Standard full-featured experience.minimal: Bare-bones UI with four corner indicators and action buttons.overlay: Focuses on the document frame and screen title.kiosk: Automated flow for unattended environments (auto-capture only).textExtract: Optimized layout for OCR-focused workflows.
- Replaced
MinimalCornerIndicatorswith standardizedCornerBoxcomponent across all modes for better consistency. - Smooth Flip Fading: Implemented opacity-based fading transitions during frame flipping for a more premium feel.
- Refined Minimal Mode Constraints: Capture animation, image cropping, and previews are now strictly pixel-perfectly bounded by the corner indicators.
- Matched Preview Aesthetics: Synchronized border radius between
CornerBoxindicators and captured image previews for a seamless visual experience.
Notes #
- Default mode behavior is unchanged — no existing consumers are affected.
- Instructions are fully supported in minimal mode but hidden by default (minimal mode always suppresses instruction overlays).
2.3.0 #
added:
- Export Format Support: Choose output format for captured documents.
outputFormatparameter: Select fromDocumentOutputFormat.jpg(default),png,pdf,webp, ortiff.pdfPageSizeparameter: Configure PDF page size (PdfPageSize.a4orletter) when using PDF format.imageQualityparameter: Control compression quality (1-100) for JPG and WebP formats.- PDF Generation: Multi-page PDF support for two-sided documents with configurable page sizes.
DocumentCaptureData.pdfPath: New field containing the path to generated PDF when using PDF format.PdfGenerationService: New exported service for custom PDF generation from images.
- TIFF Format Support: Added automatic JPG preview generation for TIFF files to resolve "Invalid image data" errors in Flutter UI.
- TIFF OCR Fix: OCR extraction now uses internal JPG previews to bypass ML Kit's lack of native TIFF support.
DocumentCaptureDataEnhancements:- Added
frontPreviewPathandbackPreviewPath: Access displayable (JPG) versions of documents even when the primary output is TIFF. - Added
hasFrontTextandhasBackTextgetters: Simplified logic for checking if OCR extracted any content.
- Added
initialFlashModeproperty: Configure the starting flash mode for the camera (auto, off, on, torch).- Library Export: Re-exported
FlashModefrom the core library to simplify integration for consumers.
changed:
- Alignment Reset: The alignment guidance (green frame) now correctly resets when tapping "Retake".
- PDF Export Optimization: Automatically deletes temporary JPG files after PDF generation to minimize local storage usage.
- Example App Enhancement: Added direct file opening for generated PDFs using
open_file. - Image Processing: Updated
ImageProcessingServiceto support multiple output formats. - Dependencies: Added
pdfpackage (^3.11.2) for PDF generation. Downgradedimagepackage to ^4.5.4 for compatibility.
notes:
- All new parameters are optional with sensible defaults.
- Existing code continues to work without modifications (JPG is default).
- PDF generation only occurs when
outputFormatis set toDocumentOutputFormat.pdf. - See
example/lib/export_format_example.dartfor usage examples of all formats.
2.2.1 2.2.3 #
- Update Readme.md
- Update metadata
- Update example
2.2.0 #
added:
- Major internal refactoring: Separated UI and business logic for better maintainability.
- Improved Architecture:
- UI split into
DocumentCameraPreviewLayerandDocumentCameraOverlayLayer. - State management and business logic extracted into
DocumentCameraLogic.
- UI split into
- New styling parameters:
showDetectionStatusTextinDocumentCameraFrame: Toggle live detection guidance text.showInstructionTextinDocumentCameraInstructionStyle: Toggle top instruction text.topPositionandrightPositioninDocumentCameraSideIndicatorStyle: Precise control over side indicator placement.
- Enhanced Internal Services:
DocumentDetectionServiceOptimization:- Added Letterbox Correction: Accounts for camera sensor aspect ratio vs display area to ensure precise frame alignment.
- Added Best-Candidate Selection: Intelligently picks the best document candidate based on aspect ratio and area.
- Added Live Guidance Engine: Generates real-time user hints ("Move closer", "Move right", etc.) via
detectionStatusNotifier. - Added Screen-Space Mapping: Automatically maps detection coordinates to screen pixels for overlay rendering, including mirroring support for front cameras.
ImageConverterServiceRobustness:- Hardened conversion paths for
BGRA8888(iOS) andNV21/YUV420(Android). - Added Stride (BytesPerRow) Handling to prevent image skewing/distortion on various hardware.
- Hardened conversion paths for
changed:
DocumentCameraFramewidget is now more efficient and easier to customize.- Refactored internal components for a cleaner codebase.
2.1.0 2.1.1 #
added:
- On-device OCR (text extraction): Optional text recognition via
enableExtractText. enableExtractTextparameter: Whentrue, runs OCR after capture and setsDocumentCaptureData.frontOcrTextandbackOcrTextbefore calling the save callback (no API key or internet required).OcrServiceclass: Reusable on-device OCR using Google ML Kit (Latin script; English and other Latin-based languages). Exported from the package for custom use.DocumentCaptureData.frontOcrTextandDocumentCaptureData.backOcrText: Optional extracted text whenenableExtractTextis true.- Dependency:
google_mlkit_text_recognitionfor OCR.
changed:
onDocumentSaved: New preferred callback name (replacesonBothSidesSaved). Fits both one-sided documents (e.g. passport) and two-sided (e.g. ID). Callback receivesDocumentCaptureDatawith image paths and, whenenableExtractTextis true,frontOcrTextandbackOcrText.onBothSidesSavedis deprecated; useonDocumentSaved. The deprecated callback still works for backward compatibility.DocumentCaptureDatamodel: Now holds optionalfrontOcrTextandbackOcrText; doc comment updated for one-sided vs two-sided use.
notes:
- OCR supports Latin script only (English, etc.). Arabic is not supported by ML Kit's on-device model.
- Android:
minSdk21+ required. iOS: platform 15.5+ and armv7 exclusion recommended for ML Kit.
2.0.1 2.0.4 #
- Update Readme.md
- Update metadata
2.0.0 #
added:
- Modular styling system with dedicated style classes:
DocumentCameraAnimationStyleDocumentCameraFrameStyleDocumentCameraButtonStyleDocumentCameraTitleStyleDocumentCameraSideIndicatorStyleDocumentCameraProgressStyleDocumentCameraInstructionStyle
- Auto-capture functionality via
enableAutoCaptureparameter. - Error handling with
onCameraErrorcallback. - Enhanced animation using
FrameCaptureAnimation. - Performance boost using
ValueListenableBuilderwithchild. - Complete Dart documentation for all style properties.
changed:
- BREAKING: Replaced individual style params with grouped
styleobjects. - BREAKING: Constructor now uses style classes (
buttonStyle,animationStyle, etc.). - Optimized animation rendering and reduced rebuilds.
- Refactored code for better structure and performance.
migration_guide: before: |
DocumentCameraFrame(
captureButtonStyle: buttonStyle,
captureButtonAlignment: Alignment.center,
captureButtonPadding: EdgeInsets.all(16),
capturingAnimationDuration: Duration(seconds: 1),
)
after: |
DocumentCameraFrame(
buttonStyle: DocumentCameraButtonStyle(
captureButtonStyle: buttonStyle,
captureButtonAlignment: Alignment.center,
captureButtonPadding: EdgeInsets.all(16),
),
animationStyle: DocumentCameraAnimationStyle(
capturingAnimationDuration: Duration(seconds: 1),
),
)
1.0.9 1.0.4 #
- Update
examples.gif - Update Readme.md
- Update metadata
1.0.3 #
- Update metadata
1.0.2 #
- Update metadata
1.0.0 #
added:
- Two-sided document capture: front and back.
- Callbacks:
onFrontCaptured,onBackCaptured,onBothSidesSaved. - Custom titles and instructions per side.
- Navigation controls and side indicator UI.
- Animated progress bar and frame flip transitions.
- Camera switching via button.
changed:
- BREAKING: Replaced
onSavedwithonBothSidesSaved. - Refactored to support two-sided logic and flow.
- Enhanced transitions and layout handling.
fixed:
- Better capture reset flow.
- Improved multi-side state handling.
- Camera-related error recovery.
0.1.6 #
- Update metadata.
0.1.5 #
features:
- Added camera switch icon. fixes:
retakeButtonTextandsaveButtonTextnow display correctly.- Custom camera selection (not hardcoded to ID 0).
0.1.4 #
- Update Readme.md.
0.1.3 #
- Update metadata.
0.1.2 #
- Added
showCloseButtonflag. - Frame animation duration reduced to
400ms.
0.1.0 #
- Redesigned
DocumentCameraFrameUI. - Added:
captureOuterCircleRadiuscaptureInnerCircleRadius
- Smooth container open animation (bottom to top).
- Documentation updated accordingly.
0.0.9 #
- Add
example.gif - Update Readme.md.
0.0.8 #
- Add
example.mp4 - Update Readme.md.
0.0.7 to 0.0.2 #
- README and metadata updates.
0.0.3 #
- Fixed deprecated usage in
DocumentCameraFramePainter:- Changed
Colors.black.withOpacity(0.5)toColors.black.withAlpha(127).
- Changed
0.0.1 #
- Initial release.