gpt4 book ai didi

flutter - 在 Flutter 中失去与设备的连接?

转载 作者:行者123 更新时间:2023-12-03 03:58:50 24 4
gpt4 key购买 nike

我在使用插件 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 :

  • NSPhotoLibraryUsageDescription - 描述为什么您的应用需要照片库的权限。这称为 Privacy - Photo Library Usage Description在可视化编辑器中。
  • NSCameraUsageDescription - 描述为什么您的应用需要访问相机。这称为 Privacy - Camera Usage Description在可视化编辑器中。
  • NSMicrophoneUsageDescription - 如果您打算录制视频,说明为什么您的应用需要访问麦克风。这称为 Privacy - Microphone Usage Description在可视化编辑器中。

  • 同样的,你需要在Android中添加权限。

    关于flutter - 在 Flutter 中失去与设备的连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58830884/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com