qrcode_flutter 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new78

qrcode_flutter #

Flutter plugin for scanning QR codes.You can customize your page by using PlatformView.Scanning Picture from path(photo album).

You can download flutter_demo.apk for testing

Usage #

class _MyAppState extends State<MyApp> {
  QRCaptureController _controller = QRCaptureController();

  bool _isTorchOn = false;

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

    _controller.onCapture((data) {
      print('$data');
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('scan'),
          actions: <Widget>[
            FlatButton(
              onPressed: () async {
                PickedFile image =
                    await ImagePicker().getImage(source: ImageSource.gallery);
                var qrCodeResult =
                    await QRCaptureController.getQrCodeByImagePath(image.path);
                print(qrCodeResult);
              },
              child: Text('photoAlbum', style: TextStyle(color: Colors.white)),
            ),
          ],
        ),
        body: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            QRCaptureView(controller: _controller),
            Align(
              alignment: Alignment.bottomCenter,
              child: _buildToolBar(),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildToolBar() {
    return Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FlatButton(
              onPressed: () {
                _controller.pause();
              },
              child: Text('pause'),
            ),
            FlatButton(
              onPressed: () {
                if (_isTorchOn) {
                  _controller.torchMode = CaptureTorchMode.off;
                } else {
                  _controller.torchMode = CaptureTorchMode.on;
                }
                _isTorchOn = !_isTorchOn;
              },
              child: Text('torch'),
            ),
            FlatButton(
              onPressed: () {
                _controller.resume();
              },
              child: Text('resume'),
            )
          ],
        );
  }
}

Integration #

iOS #

To use on iOS, you must add the following to your Info.plist

<key>NSCameraUsageDescription</key>
<string>Camera permission is required for qrcode scanning.</string>
<key>io.flutter.embedded_views_preview</key>
<true/>

1.0.0 #

提供相机扫码功能,提供照片解析功能(通过相册选择照片或者网络下载照片)

You can customize your page using by PlatformView.Scanning Picture from path(photo album).

1.0.1

Modify the document

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:qrcode_flutter/qrcode_flutter.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
  QRCaptureController _controller = QRCaptureController();

  bool _isTorchOn = false;

  String _captureText = '';

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

    _controller.onCapture((data) {
      print('$data');
      setState(() {
        _captureText = data;
      });
    });
  }

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('scan'),
          actions: <Widget>[
            FlatButton(
              onPressed: () async {
                PickedFile image =
                    await ImagePicker().getImage(source: ImageSource.gallery);
                var qrCodeResult =
                    await QRCaptureController.getQrCodeByImagePath(image.path);
                setState(() {
                  _captureText = qrCodeResult;
                });
              },
              child: Text('photoAlbum', style: TextStyle(color: Colors.white)),
            ),
          ],
        ),
        body: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            Container(
              width: 300,
              height: 300,
              child: QRCaptureView(
                controller: _controller,
              ),
            ),
            SafeArea(
              child: Align(
                alignment: Alignment.bottomCenter,
                child: _buildToolBar(),
              ),
            ),
            Container(
              child: Text('$_captureText'),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildToolBar() {
    return Row(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        FlatButton(
          onPressed: () {
            _controller.pause();
          },
          child: Text('pause'),
        ),
        FlatButton(
          onPressed: () {
            if (_isTorchOn) {
              _controller.torchMode = CaptureTorchMode.off;
            } else {
              _controller.torchMode = CaptureTorchMode.on;
            }
            _isTorchOn = !_isTorchOn;
          },
          child: Text('torch'),
        ),
        FlatButton(
          onPressed: () {
            _controller.resume();
          },
          child: Text('resume'),
        ),
      ],
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  qrcode_flutter: ^1.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:qrcode_flutter/qrcode_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
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]
78
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:qrcode_flutter/qrcode_flutter.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:qrcode_flutter/qrcode_flutter.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:qrcode_flutter/qrcode_flutter.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:qrcode_flutter/qrcode_flutter.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [qrcode_flutter] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test