barcode_scan 2.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

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 #

  • [x] Scan 2D barcodes
  • [x] Scan QR codes
  • [x] Control the flash while scanning
  • [x] 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>

v2.0.1 - 2020-02-19 #

Bugfixes:

  • Fixed wrong build.gradle

v2.0.0 - 2020-02-19 #

Features:

Bugfixes:

Changes:

  • Fix compile warning - @lookfirst
  • Upgrade gradle - @SuuSoJeat
    • com.android.tools.build:gradle: 3.3.1 -> 3.5.0
    • org.jetbrains.kotlin:kotlin-gradle-plugin: 1.3.20 -> 1.3.50
    • compileSdkVersion: 28 -> 29
    • targetSdkVersion: 28 -> 29
    • gradle: 4.10.2 -> 5.4.1
  • Package description updated - @connectety
  • README.md and LICENSE.md updated
  • Since the project owner has been changed, the package names are different. Checkout the UPGRADE.md for details.

v1.0.0 - 2018-08-30 #

Breaking Change: Adds support for AndroidX

v0.0.8 - 2018-08-30 #

v0.0.7 - 2018-08-30 #

  • Fix iOS barcodes not scanning

v0.0.6 - 2018-08-29 #

  • Fix android dependencies
  • iOS scanner now looks like Android thanks to @dustin-graham

v0.0.4 - 2018-02-8 #

  • Fix missing gradle dependency (thanks to toteto)
  • Update gradle dependencies

v0.0.3 - 2017-02-8 #

  • Improved permission handling (thanks to BenSower)
  • Added MIT license

v0.0.2 - 2017-11-7 #

v0.0.1 - 2017-10-29 #

  • Supports 2D & QR Codes
  • Control flash while scanning

example/lib/main.dart

import 'dart:async';

import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String barcode = "";

  @override
  initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Barcode Scanner Example'),
          ),
          body: new Center(
            child: new Column(
              children: <Widget>[
                new Container(
                  child: new MaterialButton(
                      onPressed: scan, child: new Text("Scan")),
                  padding: const EdgeInsets.all(8.0),
                ),
                new Text(barcode),
              ],
            ),
          )),
    );
  }

  Future scan() async {
    try {
      String barcode = await BarcodeScanner.scan();
      setState(() => this.barcode = barcode);
    } on PlatformException catch (e) {
      if (e.code == BarcodeScanner.CameraAccessDenied) {
        setState(() {
          this.barcode = 'The user did not grant the camera permission!';
        });
      } else {
        setState(() => this.barcode = 'Unknown error: $e');
      }
    } on FormatException{
      setState(() => this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
    } catch (e) {
      setState(() => this.barcode = 'Unknown error: $e');
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  barcode_scan: ^2.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:barcode_scan/barcode_scan.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
98
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
99
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.7
  • Flutter: 1.12.13+hotfix.9

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8