lutter 调用原生硬件 Api 实现扫码
2021-03-09 04:28
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}"), );
} }
文章标题:lutter 调用原生硬件 Api 实现扫码
文章链接:http://soscw.com/index.php/essay/62128.html