Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

Repository files navigation

GitHub licenseGitHub starsPubGitHub forks

DEVELOPMENT HAS BEEN DISCONTINUED

Since there are many other libraries which provides more and better functionality in barcode scanning, I decided to discontinue the development of this project. I recommend the Firebase ML Vision package as an alternative: https://pub.dev/packages/firebase_ml_vision



















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';
voidmain() async {
var result =awaitBarcodeScanner.scan();
print(result.type); // The result type (barcode, cancelled, failed)print(result.rawContent); // The barcode contentprint(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';
voidmain() async {
var options =ScanOptions(
// set the options
);
var result =awaitBarcodeScanner.scan(options: options);
// ...
}

Supported options

OptionTypeDescriptionSupported by
strings.cancelStringThe cancel button text on iOSiOS only
strings.flash_onStringThe flash on button textiOS + Android
strings.flash_offStringThe flash off button textiOS + Android
restrictFormatBarcodeFormat[]Restrict the formats which are recognizediOS + Android
useCameraintThe index of the camera which is used for scanning (See BarcodeScanner.numberOfCameras)iOS + Android
autoEnableFlashboolEnable the flash when start scanningiOS + Android
android.aspectTolerancedoubleEnable auto focus on AndroidAndroid only
android.useAutoFocusboolSet aspect ratio tolerance level used in calculating the optimal Camera preview sizeAndroid 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)

About

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

Resources

Stars

620 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages