qr_code_scanner 0.0.12

  • Readme
  • Changelog
  • Example
  • Installing
  • 95

QR Code Scanner #

Build Status

A QR code scanner that works on both iOS and Android by natively embedding the platform view within Flutter. The integration with Flutter is seamless, much better than jumping into a native Activity or a ViewController to perform the scan.

Screenshots #

Android

iOS

Get Scanned QR Code #

When a QR code is recognized, the text identified will be set in 'qrText'.

class _QRViewExampleState extends State<QRViewExample> {
  final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
  var qrText = "";
  QRViewController controller;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Expanded(
            flex: 5,
            child: QRView(
              key: qrKey,
              onQRViewCreated: _onQRViewCreated,
            ),
          ),
          Expanded(
            flex: 1,
            child: Center(
              child: Text('Scan result: $qrText'),
            ),
          )
        ],
      ),
    );
  }

  void _onQRViewCreated(QRViewController controller) {
    this.controller = controller;
    controller.scannedDataStream.listen((scanData) {
      setState(() {
        qrText = scanData;
      });
    });
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }
}

iOS Integration #

In order to use this plugin, add the following to your Info.plist file:

<key>io.flutter.embedded_views_preview</key>
<true/>

Flip Camera (Back/Front) #

The default camera is the back camera.

controller.flipCamera();

Flash (Off/On) #

By default, flash is OFF.

controller.toggleFlash();

Resume/Pause #

Pause camera stream and scanner.

controller.pause();

Resume camera stream and scanner.

controller.resume();

TODO'S: #

  • iOS Native embedding is written to match what is supported in the framework as of the date of publication of this package. It needs to be improved as the framework support improves.
  • In future, options will be provided for default states.
  • Finally, I welcome PR's to make it better :), thanks

Credits #

0.0.12 #

  • Add optional parameter to use a camera overlay.
  • Simplfiy controller, expose scanDataStream.
  • Fix for Android flash toggle.
  • Add ability to pause/resume the camera.
  • Thanks! to Luis Thein for all the above contributions.

0.0.11 #

  • android build break fix

0.0.10 #

  • update README.md

0.0.9 #

  • update README.md

0.0.8 #

  • migrated Android project to androidx (by Felipe César)
  • migrated iOS to Swift 5 (by Felipe César)

0.0.7 #

  • flash light support added

0.0.6 #

  • camera flip added

0.0.5 #

  • preview stretching after change screen orientation fix

0.0.4 #

  • fix black screen orientation/unlock/focus

0.0.3 #

  • iOS library reference fix
  • Android pause/resume fix

0.0.2 #

  • Added documentation to cover how to use the plugin.

0.0.1 #

  • QR Code scanner embedded inside flutter.

example/README.md

qr_code_scanner #

Demonstrates how to use the qr_code_scanner plugin.

iOS Support: #

info.plist #

<dict>
    <key>io.flutter.embedded_views_preview</key>
	<true/>
	<key>UIBackgroundModes</key>
	<array>
		<string>fetch</string>
		<string>remote-notification</string>
	</array>
	<key>NSCameraUsageDescription</key>
    <string>Can we access your camera in order to scan barcodes?</string>
</dict>

Example: #

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

void main() => runApp(MaterialApp(home: QRViewExample()));

class QRViewExample extends StatefulWidget {
  const QRViewExample({
    Key key,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() => _QRViewExampleState();
}

class _QRViewExampleState extends State<QRViewExample> {
  final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
  var qrText = "";
  QRViewController controller;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Expanded(
            child: QRView(
              key: qrKey,
              onQRViewCreated: _onQRViewCreated,
            ),
            flex: 4,
          ),
          Expanded(
            child: Column(children:
              <Widget>[
                Text("This is the result of scan: $qrText"),
                RaisedButton(
                  onPressed: (){
                    if(controller != null){
                      controller.flipCamera();
                    }
                  },
                  child: Text(
                      'Flip',
                      style: TextStyle(fontSize: 20)
                  ),
                )
              ],
            ),
            flex: 1,
          )
        ],
      ),
    );
  }

  void _onQRViewCreated(QRViewController controller) {
    final channel = controller.channel;
    controller.init(qrKey);
    this.controller = controller;
    channel.setMethodCallHandler((MethodCall call) async {
      switch (call.method) {
        case "onRecognizeQR":
          dynamic arguments = call.arguments;
          setState(() {
            qrText = arguments.toString();
          });
      }
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  qr_code_scanner: ^0.0.12

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:qr_code_scanner/qr_code_scanner.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
94
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
95
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

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