【发布时间】:2019-08-15 10:55:43
【问题描述】:
只要我点击相机按钮,应用就会崩溃。
它也没有要求任何许可。
我在清单中也包含了活动文件
这是我正在使用的代码,我正在使用的插件是barcode_scan:
即使搜索了很多,我也无法解决问题。 我们将不胜感激。
class _AuditPage extends State<AuditPage>{
String result = "Scan The Barcode!";
Future _scanQR() async{
try{
String qrCode = await BarcodeScanner.scan();
setState(() {
result = qrCode;
});
}on PlatformException catch (ex){
if(ex.code==BarcodeScanner.CameraAccessDenied){
setState(() {
result="Camera Permission Was Denied";
});
}else{
setState(() {
result="Unknown Error $ex!";
});
}
} on FormatException {
setState(() {
result = "You Pressed The Back Button Before Scanning";
});
} catch (ex){
setState(() {
result="Unknown Error $ex!";
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text("Bhaifi"),
),
drawer: DrawerPage(),
body: Center(
child:Text(
result,
),
),
floatingActionButton:FloatingActionButton.extended(
icon: Icon(Icons.camera_alt),
label: Text("Scan"),
onPressed: _scanQR,
),
floatingActionButtonLocation:FloatingActionButtonLocation.centerFloat,
);
}
}
【问题讨论】:
-
你想看看AndroidX问题:我有类似的情况,你可以从这篇文章中获取一些代码:stackoverflow.com/questions/55223002/…不是解决方案或更新,而是我在原帖中的故障排除;希望对你有帮助
-
谢谢,但不工作
-
尝试使用“旧的”:barcode_scan: ^0.0.8 ,如果不工作尝试不使用“^”:只需“barcode_scan: 0.0.8”
-
不要指定barcode_scan的版本,它会为你添加合适的版本。
标签: android dart flutter barcode