scan_preview 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

scan_preview #

A QR code scanner flutter plugin project. Using PlatfromView to open native camera page scan qr code.

Installation #

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

dependencies:  
  scan_preview: ^1.0.0

Getting Started #

android: barcodescanner ios: MTBBarcodeScanner

This plugin is based on PlatformView, which means you can customize the scanning UI freely. By the way, the framing UI is limited to the native API, and only a part of the attribute customization can be provided.

How to use #

class ScanPreviewPage extends StatefulWidget {
  @override
  _ScanPreviewPageState createState() => _ScanPreviewPageState();
}

class _ScanPreviewPageState extends State<ScanPreviewPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Scan barcode example'),
        ),
        body: SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: ScanPreviewWidget(
            onScanResult: (result) {
              debugPrint('scan result: $result');
              Navigator.pop(context, result);
            },
          ),
        ),
      ),
    );
  }
}

About Permission : You should request the camear permission by yourself, I use PermissionHandler to request camera permission in this example.

ios #

You need to include the following Info.plist key in order to request camera access or the application will crash:

<key>NSCameraUsageDescription</key>
<string>Can we access your camera in order to scan barcodes?</string>

Important: Adding a boolean property to the Info.plist

<key>io.flutter.embedded_views_preview</key>
<Boolean>YES</string>

android #

Use directly.

TODO #

I am an android developer, there are still many features of ios that are not implemented.

If you are an ios developer, welcome to contribute your code.

  • [x] ios to be tested
  • [ ] ios scan radar
  • [ ] read code from gallery

Warning #

On android device and in debug mode, the camera preview will stuck sometimes, but it did not happen in release mode.

0.0.1 #

  • initial the plugin

1.0.0 #

  • Implement basic features

1.0.1 #

  • format code

1.0.2 #

update description #

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:scan_preview/scan_preview_widget.dart';
import 'package:flutter/foundation.dart';

void main() => runApp(MaterialApp(
      home: MyApp(),
    ));

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

class _MyAppState extends State<MyApp> {
  String _result = '';

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

  _requestPermission() async {
    await Permission.camera.request();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Scan barcode example'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            RaisedButton(
              child: Text('start scan'),
              onPressed: () async {
                final result = await Navigator.push(this.context,
                    MaterialPageRoute(builder: (context) => ScanPreviewPage()));
                setState(() {
                  _result = result;
                });
              },
            ),
            Text('scanl result: $_result')
          ],
        ),
      ),
    );
  }
}

class ScanPreviewPage extends StatefulWidget {
  @override
  _ScanPreviewPageState createState() => _ScanPreviewPageState();
}

class _ScanPreviewPageState extends State<ScanPreviewPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Scan barcode example'),
        ),
        body: SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: ScanPreviewWidget(
            onScanResult: (result) {
              debugPrint('scan result: $result');
              Navigator.pop(context, result);
            },
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  scan_preview: ^1.0.2

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:scan_preview/scan_preview.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
63
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]
82
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:scan_preview/scan_preview.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:scan_preview/scan_preview.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:scan_preview/scan_preview.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:scan_preview/scan_preview.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • scan_preview that is 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 2.1.0-nullsafety
Dev dependencies
flutter_test