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
- use
ScanView
Insert the Widget tree to display the scan screen - Can be defined in proportion to the size of identifiable two-dimensional code area
- through
Scan.parse(path)
Parse the qr code in the picture
Introduce plug-in and client permission configurations
- Introducing plug-ins
pubspec.yaml
dependencies:
scan: ^ 0.0.3
Copy the code
- Android configuration
AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE"/>
Copy the code
- Ios configuration
info.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
- Import in the page
import "package:scan/scan.dart"
Copy the code
- Call API
- Used in the Widget tree
ScanView
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