code_scan 0.4.10 copy "code_scan: ^0.4.10" to clipboard
code_scan: ^0.4.10 copied to clipboard

A flexible code scanner for QR codes, barcodes and many others. Using Google's ML Kit. Use it as a Widget with a camera or use the methods provided, with a camera controller.

Pub.dev package GitHub repository

Code Scanner #

A flexible code scanner for QR codes, barcodes and many others. Using Google's ML Kit. Use it as a Widget with a camera or use the methods provided, with a camera controller.

Features #

  • Scan Linear and 2D formats: QR Code, Barcode, ...
  • Widget with integrated camera
  • Listen for callbacks with every code scanned
  • Choose which formats to scan
  • Overlay the camera preview with a custom view
  • Camera lifecycle

Scannable Formats #

  • Aztec
  • Codabar
  • Code 39
  • Code 93
  • Code 128
  • Data Matrix
  • EAN-8
  • EAN-13
  • ITF
  • PDF417
  • QR Code
  • UPC-A
  • UPC-E

Getting started #

Install it using pub:

flutter pub add code_scan

And import the package:

import 'package:code_scan/code_scan.dart';

Usage #

CodeScanner(
    onScan: (code, details, controller) => setState(() => this.code = code),
    onScanAll: (codes, controller) => print('Codes: ' + codes.map((code) => code.rawValue).toString()),
    formats: [ BarcodeFormat.qrCode ],
    once: true,
)

Add callbacks for events:

CodeScanner(
    onScan: (code, details, controller) => ...,
    onScanAll: (codes, controller) => ...,
    onCreated: (controller) => ...,
)

Set loading and overlay widgets, although you can use the default overlay:

CodeScanner(
    loading: Center(child: CircularProgressIndicator()),
    overlay: Center(child: Text('Scanning...')),
)

Choose how the widget should react:

CodeScanner(
    direction: CameraLensDirection.back,
    resolution: ResolutionPreset.medium,
    formats: const [ BarcodeFormat.all ],
    scanInterval: const Duration(seconds: 1),
    aspectRatio: 480 / 720, // height / width
    once: false,
)

The default behavior of the widget is to fill the screen or parent widget, but you can choose the aspect ratio.

You can use the camera view with your camera controller, without having the scanning widget:

final cameraController = CameraController();

CodeScannerCameraView(
    controller: cameraController,
)

Caution #

If you use your camera controller, it's recommended that you be responsible to control camera resources.

Manage it yourself using the lifecycle or make sure it's already being managed by some other widget.

Methods provided #

Create a camera listener and plug it with any camera controller, to scan for codes:

final cameraController = CameraController();

final listener = CodeScannerCameraListener(
    cameraController,
    
    formats: const [ BarcodeFormat.all ],
    interval: const Duration(milliseconds: 500),
    once: false,
    
    onScan: (code, details, controller) => ...,
    onScanAll: (codes, controller) => ...,
);

Stop the listener whenever you want:

listener.stop();

GitHub #

The package code is available on Github: Flutter - CodeScanner

16
likes
150
pub points
81%
popularity

Publisher

verified publisherdrafakiller.com

A flexible code scanner for QR codes, barcodes and many others. Using Google's ML Kit. Use it as a Widget with a camera or use the methods provided, with a camera controller.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

camera, flutter, google_mlkit_barcode_scanning, rxdart

More

Packages that depend on code_scan