code_scan 0.1.0 copy "code_scan: ^0.1.0" to clipboard
code_scan: ^0.1.0 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 camera or use the methods provided, with whatever camera widget.

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 whatever camera widget.

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

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,
)

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

15
likes
0
pub points
82%
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 camera or use the methods provided, with whatever camera widget.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

camera, flutter, google_mlkit_barcode_scanning, rxdart

More

Packages that depend on code_scan