使用插件image_picker时遇到问题:“0.6.1 + 11”和
条码扫描:“^ 1.0.0”。首先,我扫描条形码,然后从相机拍摄照片。
问题是大多数情况下,Android应用从相机拍摄图像而没有任何日志后会自行重启。该日志仅显示“与设备的连接断开”。
这是代码:
Future scanCarton() async {
try {
String barcode = await BarcodeScanner.scan();
await getImage().then((imageFile){
if (imageFile != null){
Map<String,String>requestData = new Map<String,String>();
requestData["content"] = barcode;
requestData["type"] = "carton";
requestData["mode"] = "job";
if (widget.orderData.product_type.toLowerCase() == "batched"){
requestData["carton_id"] = "0";
}else{
requestData["carton_id"] = "${scannedCartonCount + 1}";
}
if(this.mounted){
setState(() {
_isLoading = true;
});
}else{
print("Gotcha 2");
}
upload(imageFile, UrlFile.UPLOAD_SCAN_IMAGE, "carton", requestData).then((value){
if(this.mounted){
setState(() {
_isLoading = false;
});
}else{
print("Gotcha 4");
}
incrementCartonCount();
if(widget.orderData.product_type.toLowerCase() == "batched"){
openNextCartonPopup();
}
});
}
});
} on PlatformException catch (e) {
if (e.code == BarcodeScanner.CameraAccessDenied) {
print('The user did not grant the camera permission!');
} else {
print('Unknown error $e') ;
}
} on FormatException{
print( 'null (User returned using the "back"-button before scanning anything. Result)');
} catch (e) {
print('Unknown error: $e');
}
}
最佳答案
您只需要配置即可事先获得许可。
对于iOS,将以下密钥添加到位于Info.plist
的<project root>/ios/Runner/Info.plist
文件中:
Privacy - Photo Library Usage Description
。 Privacy - Camera Usage Description
。 Privacy - Microphone Usage Description
。 同样,您需要在Android中添加权限。
关于flutter - 在Flutter中失去与设备的连接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58830884/