Code Monkey home page Code Monkey logo

fast_barcode_scanner's Introduction

fast_barcode_scanner

Fast barcode & QR code scanning library using the latest technologies on Android and iOS.

It provides a live preview widget you can put anywhere in your widget tree with rich configurability.

"Buy Me A Coffee"

Installation

This plugin required iOS 11.0 and Android API level 21 or higher.

Add the following line to your pubspec.yaml:

fast_barcode_scanner: ^2.0.0-dev.2

iOS

Add the NSCameraUsageDescription key to your ios/Runner/Info.plist, like so:

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

Android

Change the minimum Android api level to 21 (or higher) in your android/app/build.gradle file.

minSdkVersion 21

Usage

Insert the BarcodeCamera anywhere in your widget tree to get a live camera preview:

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 and QR code Scanner')),
            body: BarcodeCamera(
                types: const [
                    BarcodeType.ean8,
                    BarcodeType.ean13,
                    BarcodeType.code128,
                    BarcodeType.qr
                ],
                resolution: Resolution.hd720,
                framerate: Framerate.fps30,
                position: CameraPosition.back,
                mode: DetectionMode.pauseVideo,
                onScan: (code) => print(code),
                children: [
                    MaterialPreviewOverlay(animateDetection: false),
                    BlurPreviewOverlay(),
                    Positioned(
                      child: ElevatedButton(
                        onPressed: () =>
                            CameraController.instance.resumeDetector(),
                        child: Text('Resume'),
                      ),
                    )
                ],
            )
        )
    }
}

Two overlays are included:

  • MaterialPreviewOverlay mimics the official material barcode scanning example.
  • BlurPreviewOverlay blurs the screen when a barcode or QR code is detected.

Controlling the camera

The CameraController-singleton manages the camera. Normally when using BarcodeCamera you don't need CameraController.

To get access use the following anyhwere in your code:

final controller = CameraController()

Here is a full list of all the methods CameraController provides:

method Description
initialize Initializes the scanner with the provided config
pauseDetector Actively pauses the scanner
resumeDetector Resumes the scanner from the paused state
toggleTorch toggles the torch on and off
changeConfiguration Push an updated ScannerConfiguration
analyzeImage
dispose Stops and resets the camera on platform level

CameraState

The state comes in handy when building overlays that change depending on it. You can access the state by using CameraController().state.

Attribute Description
isInitialized Indicated whether the camera is currently initialized
previewConfig The current PreviewConfiguration
scannerConfig The current ScannerConfiguration
eventNotifier Notifies listeners of CameraEvents
torchState The current state of the torch (on/off)
hasError Indicates if error is null or not
error Access the most recent error

fast_barcode_scanner's People

Contributors

tarang1998 avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.