fast_barcode_scanner 1.0.1 copy "fast_barcode_scanner: ^1.0.1" to clipboard
fast_barcode_scanner: ^1.0.1 copied to clipboard

outdated

A fast barcode scanner using MLKit on Android and AVFoundation on iOS.

fast_barcode_scanner #

A fast barcode scanner using MLKit (and CameraX) on Android and AVFoundation on iOS. This package leaves the UI up to the user, but rather gives an access to a camera preview.

Installation #

Add the following line to your pubspec.yaml:

fast_barcode_scanner: ^1.0.0

iOS specific #

iOS required to add the NSCameraUsageDescription key to your Info.plist Add a description under the NSCameraUsageDescription key to your Info.plist like so:

<key>NSCameraUsageDescription</key>
<string>This app requires access to your phone’s camera solely for scanning barcodes</string>

Usage #

The barcode scanner consists of two main classes CameraController and BarcodeCamera. A full example looks like this:

import 'package:fast_barcode_scanner/fast_barcode_scanner.dart';

class MyScannerScreen extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(title: Text('Barcode Scanner')),
            body: BarcodeCamera(
                types: const [
                    BarcodeType.ean8,
                    BarcodeType.ean13,
                    BarcodeType.code128
                ],
                resolution: Resolution.hd720,
                framerate: Framerate.fps30,
                mode: DetectionMode.pauseVideo,
                onScan: (code) => print(code),
                children: [
                    MaterialPreviewOverlay(animateDetection: false),
                    BlurPreviewOverlay(),
                    Positioned(
                      child: ElevatedButton(
                        onPressed: () =>
                            CameraController.instance.resumeDetector(),
                        child: Text('Resume'),
                      ),
                    )
                ],
            )
        )
    }
}

As you can see, there are two overlays in the childrens list. These two are included in the package. MaterialPreviewOverlay mimics the official material barcode scanning example. BlurPreviewOverlay blurs the screen when a barcode is detected and unblurs it on resuming.

CameraController #

The CameraController-singleton manages the camera. It handles all the low level stuff like communicating with native code. It is implemented as a singleton to guarantee that there is always one and the same controller managing the camera. You can access the controller via the CameraController.instance attribute. These are the accessible methods:

method Description
initialize Initialized the scanner with the provided config
pauseDetector Actively pauses the scanner
resumeDetector Resumes the scanner when it is paused
toggleTorch toggles the torch on and off
dispose Stops and resets the camera on native level

You do not have to call initialize by yourself, if you use the BarcodeCamera widget. If you want to use your own widget however, have a look at CameraController.instance.state, which contains a PreviewConfiguration after initialization. This class contains all necessary information to build a preview widget yourself.

BarcodeCamera #

The BarcodeCamera is a widget showing a preview of the camera feed. It calls the CameraController in the background for initialization and configuration of the barcode camera.

An overview of all possible configurations (either passed to BarcodeCamera or CameraController.initialize):

Attribute Description
types See code types to scan (see BarcodeType)
mode Whether to pause the camera on detection
resolution The resolution of the camera feed
framerate The framerate of the camera feed
position Choose betreen back and front camera
onScan The callback when a barcode is scanned
children Child widgets to display on top
54
likes
0
pub points
90%
popularity

Publisher

unverified uploader

A fast barcode scanner using MLKit on Android and AVFoundation on iOS.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

fast_barcode_scanner_platform_interface, flutter

More

Packages that depend on fast_barcode_scanner