Two-dimensional code barcode scan code

A, Flutter two-dimensional code scanning barcode plug-in
https://pub.dev/packages/barcode_scan
1, the installation
dependencies:
barcode_scan: ^1.0.0
2, configure permissions
Add the camera permission to your AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
Add the BarcodeScanner activity to your AndroidManifest.xml. Do NOT
modify the name.
<activity
android:name="com.apptreesoftware.barcodescan.BarcodeScannerActivity"/>
3, check the configuration of the Hubei Public build.gradle ape Teng Network Technology Co.,
3.1 Edit your android directory of build.gradle (Edit your project-level
build.gradle file to look like this)
Note: The official version kotlin_version document configuration is 1.2.31, 1.2.31 but found the actual error. So this project uses 1.3.0.
buildscript {
ext.kotlin_version = '1.3.0'
...
dependencies {
...
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
...
3.2 Edit your android / app directory below build.gradle (Edit your app-levelbuild.gradle file to look like this)
apply plugin: 'kotlin-android'
...
dependencies {
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
...
}
4, using
import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/services.dart';
class ScanPage extends StatefulWidget {
ScanPage({Key key}) : super(key: key);
_ScanPageState createState() => _ScanPageState();
}
class _ScanPageState extends State <ScanPage> {public ape Hubei Teng Network Technology Co., Ltd.
was barcode;
Future _scan() async {
try {
String barcode = await BarcodeScanner.scan();
setState(() {
return this.barcode = barcode;
});
} on PlatformException catch (e) {
if (e.code == BarcodeScanner.CameraAccessDenied) {
setState(() {
return this.barcode = 'The user did not grant the camera
permission!';
});
} else {
setState(() {
return this.barcode = 'Unknown error: $e';
});
}
} on FormatException{
setState(() => this.barcode = 'null (User returned using the
"back"-button before scanning anything. Result)');
} catch (e) {
setState(() => this.barcode = 'Unknown error: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.camera_roll),
onPressed: _scan,
),
appBar: AppBar (
title: Text("扫码"),
),
body:Text("扫码--${barcode}"),
);
}
}
 
Two, Flutter use barcode_scan suggest the following error Solution
Android dependency ‘androidx.core:core’ has different version for the compile (1.0.0)
and runtime (1.0.2) classpath. You should manually set the same version via
DependencyResolution
http://bbs.itying.com/topic/5d0468735923fe0334c35ea2

Guess you like

Origin www.cnblogs.com/zhaofeis/p/12375019.html