document_frame_scanner 0.0.2

SDKflutter
Platformandroidios

Capture and Crop your document images with a customizable camera interface using this flutter package.

Document Frame Scanner

The DocumentFrameScanner package streamlines the process of scanning documents with a flexible camera interface designed for capturing and trimming document images. It's perfect for apps needing quick and intuitive document scanning solutions.

Features

  • Document Frame: Adjustable frame size for precise document scanning.
  • Camera Preview: Live camera feed offering real-time visual feedback.
  • Intuitive Controls:
    • Capture: Snap a photo of the document.
    • Save: Store the scanned image.
    • Retake: Retake if the result isn’t satisfactory.
  • Customizable Interface:
    • Set frame dimensions, button designs, and placement.
    • Include optional titles with customizable alignment and spacing.
  • Event Listeners: Effortlessly manage actions like onCaptured, onSaved, and onRetake.

Installation

Add the package to your Flutter project using:

flutter pub add document_frame_scanner

Then run:

flutter pub get

Setup

iOS Setup

Add the following keys to your ios/Runner/Info.plist file to request camera and microphone permissions:


<plist version="1.0">
    <dict>
        <!-- Add the following keys inside the <dict> section -->
        <key>NSCameraUsageDescription</key>
        <string>We need camera access to capture documents.</string>
        <key>NSMicrophoneUsageDescription</key>
        <string>We need microphone access for audio-related features.</string>
    </dict>
</plist>

Android Setup

  1. Update the minSdkVersion to 21 or higher in android/app/build.gradle:
android {
    defaultConfig {
        minSdk 21
    }
}
  1. Add these permissions to your AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <application android:label="MyApp" android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <!-- Activities and other components -->
    </application>

</manifest>

Managing Camera Access Permissions

When initializing the camera, you might encounter permission-related errors that need to be handled appropriately. Below is a list of potential error codes and their meanings:

Error CodeMeaning
CameraAccessDeniedThe user has denied permission to access the camera.
CameraAccessDeniedWithoutPromptiOS only: The user previously denied camera access and must manually enable it in Settings.
CameraAccessRestrictediOS only: Camera access is restricted, such as through parental controls.
AudioAccessDeniedThe user has denied permission to access the microphone.
AudioAccessDeniedWithoutPromptiOS only: The user previously denied microphone access and must manually enable it in Settings.
AudioAccessRestrictediOS only: Microphone access is restricted, such as through parental controls.

Usage

Import the Package

import 'package:document_frame_scanner/document_frame_scanner.dart';

Example

import 'package:document_frame_scanner/document_frame_scanner.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(title: const Text('Document Frame Scanner')),
        body: Center(
          child: ElevatedButton(
            onPressed: () => Navigator.of(context).push(
              MaterialPageRoute(builder: (_) => const DocumentFrameScannerExample()),
            ),
            child: const Text('Start Document Capture'),
          ),
        ),
      ),
    );
  }
}

class DocumentFrameScannerExample extends StatelessWidget {
  const DocumentFrameScannerExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: DocumentFrameScanner(
        frameWidth: 300.0,
        frameHeight: 200.0,
        title: const Text(
          'Capture Your Document',
          style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
        ),
        showCloseButton: true,
        onCaptured: (imgPath) => debugPrint('Captured image path: $imgPath'),
        onSaved: (imgPath) => debugPrint('Saved image path: $imgPath'),
        onRetake: () => debugPrint('Retake button pressed'),
      ),
    );
  }
}


Widget Parameters

ParameterTypeDescriptionRequiredDefault Value
frameWidthdoubleWidth of the document capture frame.✅—
frameHeightdoubleHeight of the document capture frame.✅—
titleWidget?Optional widget to display as the screen title.❌null
screenTitleAlignmentAlignment?Alignment of the screen title.❌Alignment.topCenter
screenTitlePaddingEdgeInsets?Padding for the screen title.❌EdgeInsets.zero
captureButtonTextString?Text for the "Capture" button.❌"Capture"
captureButtonTextStyleTextStyle?Text style for the "Capture" button.❌null
captureButtonStyleButtonStyle?Style for the "Capture" button.❌null
captureButtonAlignmentAlignment?Alignment of the "Capture" button.❌Alignment.bottomCenter
captureButtonPaddingEdgeInsets?Padding for the "Capture" button.❌null
onCapturedFunction(String)Callback triggered when an image is captured.✅—
saveButtonTextString?Text for the "Save" button.❌"Save"
saveButtonStyleButtonStyle?Style for the "Save" button.❌null
saveButtonAlignmentAlignment?Alignment of the "Save" button.❌Alignment.bottomRight
onSavedFunction(String)Callback triggered when an image is saved.✅—
retakeButtonTextString?Text for the "Retake" button.❌"Retake"
retakeButtonStyleButtonStyle?Style for the "Retake" button.❌null
onRetakeVoidCallback?Callback triggered when the "Retake" button is pressed.❌null
frameBorderBoxBorder?Border for the displayed frame.❌null
capturingAnimationDurationDuration?Duration of the capturing animation.❌Duration(milliseconds: 1000)
capturingAnimationColorColor?Color of the capturing animation.❌Colors.black26
capturingAnimationCurveCurve?Curve for the capturing animation.❌Curves.easeInOut
outerFrameBorderRadiusdoubleRadius for the outer frame's border.❌12.0
innerCornerBroderRadiusdoubleRadius for the inner corners of the frame.❌8.0
animatedFrameDurationDurationDuration for the frame animation.❌Duration(milliseconds: 400)
animatedFrameCurveCurveCurve for the frame animation.❌Curves.easeIn
bottomFrameContainerChildWidget?Custom widget for the bottom container.❌null
showCloseButtonboolWhether to show a Close button.❌false

License

This project is licensed under the MIT License. See the LICENSE file for details.