The qr code scanning function is implemented to make use of the native View, which is convenient for developers to customize the layout and can be customized to embed the widget tree.

scanscan

If you need to generate qr code picture qR_flutter

Function support

  1. useScanViewInsert the Widget tree to display the scan screen
  2. Can be defined in proportion to the size of identifiable two-dimensional code area
  3. throughScan.parse(path)Parse the qr code in the picture

Introduce plug-in and client permission configurations

  1. Introducing plug-inspubspec.yaml
dependencies:
  scan: ^ 0.0.3
Copy the code
  1. Android configurationAndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE"/>
Copy the code
  1. Ios configurationinfo.list
<key>NSCameraUsageDescription</key> <string> Obtain the camera permission to use the scan function </string> <key> IO. Prepareded_views_preview </key> <string>YES</string>Copy the code

Method of use

  1. Import in the page
import "package:scan/scan.dart"
Copy the code
  1. Call API
  • Used in the Widget treeScanView
ScanController controller = ScanController();
String qrcode = 'Unknown';

Container(
  width: 250.// custom wrap size
  height: 250,
  child: ScanView(
    controller: controller,
Custom scan area, if set to 1.0, will scan full area
    scanAreaScale: 7.,
    scanLineColor: Colors.green.shade400,
    onCapture: (data) {
      // use data do something},),),Copy the code
  • Pause or resume scanning
ScanController controller = ScanController();
// ...
controller.resume();
controller.pause();
Copy the code
  • Parse the QR code from the picture
String result = await Scan.parse(imagePath);
Copy the code

Select the album image images_picker

  • Turn on/off the flash
controller.toggleTorchMode();
Copy the code

Welcome star and Issue

github