效果
使用??
QR Code Scanner
A Flutter plugin to scanning. Ready for Android
permission:
<uses-permission android:name="android.permission.CAMERA" />
Installation
Add this to your package's pubspec.yaml file:
dependencies:
qrscan: ^0.2.10
Usage example
import 'package:qrscan/qrscan.dart' as scanner;
String barcode = await scanner.scan();
Contribute
We would ?? to see your contribution!
Example
import 'package:flutter/services.dart';
import 'package:qrscan/qrscan.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String barcode = "";
@override
initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Qrcode Scanner Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text(barcode),
MaterialButton(
onPressed: scan,
child: Text("Scan"),
color: Colors.blue,
textColor: Colors.white,
),
],
),
),
),
);
}
Future scan() async {
try {
String barcode = await Qrscan.scan();
setState(() => this.barcode = barcode);
} on PlatformException catch (e) {
if (e.code == Qrscan.CameraAccessDenied) {
setState(() {
this.barcode = 'The user did not grant the camera permission!';
});
} else {
setState(() => 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');
}
}
}