Git Product home page Git Product logo

flutter_barcode_reader's Introduction

GitHub license GitHub stars Pub GitHub forks

Barcode Scanner

A flutter plugin for scanning 2D barcodes and QR codes.

This provides a simple wrapper for two commonly used iOS and Android libraries:

iOS: https://github.com/mikebuss/MTBBarcodeScanner

Android: https://github.com/dm77/barcodescanner

Features

  • Scan 2D barcodes
  • Scan QR codes
  • Control the flash while scanning
  • Permission handling

Getting Started

Android

For Android, you must do the following before you can use the plugin:

  • Add the camera permission to your AndroidManifest.xml

    <uses-permission android:name="android.permission.CAMERA" />

  • This plugin is written in Kotlin. Therefore, you need to add Kotlin support to your project. See installing the Kotlin plugin.

Edit your project-level build.gradle file to look like this:

buildscript {
    ext.kotlin_version = '1.3.61'
    // ...
    dependencies {
        // ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
// ...

Edit your app-level build.gradle file to look like this:

apply plugin: 'kotlin-android'
// ...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // ...
}

Now you can depend on the barcode_scan plugin in your pubspec.yaml file:

dependencies:
    # ...
    barcode_scan: any

Click "Packages get" in Android Studio or run flutter packages get in your project folder.

iOS

To use on iOS, you must add the the camera usage description to your Info.plist

<dict>
    <!-- ... -->
    <key>NSCameraUsageDescription</key>
    <string>Camera permission is required for barcode scanning.</string>
    <!-- ... -->
</dict>

Usage

import 'package:barcode_scan/barcode_scan.dart';

void main() async {
  var result = await BarcodeScanner.scan();
  
  print(result.type); // The result type (barcode, cancelled, failed)
  print(result.rawContent); // The barcode content
  print(result.format); // The barcode format (as enum)
  print(result.formatNote); // If a unknown format was scanned this field contains a note
}

Advanced usage

You can pass options to the scan method:

import 'package:barcode_scan/barcode_scan.dart';

void main() async {
  
  var options = ScanOptions(
    // set the options
  );

  var result = await BarcodeScanner.scan(options: options);
  
  // ...
}

Supported options

Option Type Description Supported by
strings.cancel String The cancel button text on iOS iOS only
strings.flash_on String The flash on button text iOS + Android
strings.flash_off String The flash off button text iOS + Android
restrictFormat BarcodeFormat[] Restrict the formats which are recognized iOS + Android
useCamera int The index of the camera which is used for scanning (See BarcodeScanner.numberOfCameras) iOS + Android
autoEnableFlash bool Enable the flash when start scanning iOS + Android
android.aspectTolerance double Enable the flash when start scanning Android only
android.useAutoFocus bool Enable the flash when start scanning Android only

Development setup

Setup protobuf

Mac:

$ brew install protobuf
$ brew install swift-protobuf

Windows / Linux: https://github.com/protocolbuffers/protobuf#protocol-compiler-installation

Activate the protobuf dart plugin: $ pub global activate protoc_plugin

Install theProtobuf Support plugin for IDEA / Android Studio or vscode-proto3 for VS Code

If you changed the protos.proto you've to execute the ./generate_proto.sh to update the dart / swift sources

Common problems

Android "Could not find org.jetbrains.kotlin:kotlin-stdlib-jre..."

Change org.jetbrains.kotlin:kotlin-stdlib-jre to org.jetbrains.kotlin:kotlin-stdlib-jdk (StackOverflow)

flutter_barcode_reader's People

Contributors

devtronic avatar matthewtsmith avatar bensower avatar johnpryan avatar dustin-graham avatar subin-ezto avatar toteto avatar ethael avatar santiihoyos avatar ammaratef45 avatar bcko avatar connectety avatar lookfirst avatar leontappe avatar namanshergill avatar barredterra avatar tgezginis avatar ulfsauer0815 avatar mjafartp avatar victoraldir avatar

Watchers

James Cloos 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.