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

使用插件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');
    }
  }
nieodie 回答:在Flutter中失去与设备的连接?

尝试使用Dispose()方法

  @override
  void dispose() {
    [your mathod name].dispose();
    super.dispose();
}
,

您只需要配置即可事先请求许可。

对于iOS,将以下密钥添加到位于PATH_MAX的{​​{1}}文件中:

  • NSPhotoLibraryUsageDescription -描述为什么您的应用需要照片库权限。在视觉编辑器中称为strace
  • NSCameraUsageDescription -描述为什么您的应用需要访问相机。在可视编辑器中称为Info.plist
  • NSMicrophoneUsageDescription -描述了如果您打算录制视频,为什么您的应用程序需要使用麦克风。在视觉编辑器中称为<project root>/ios/Runner/Info.plist

以同样的方式,您需要在Android中添加权限。

,

我遇到了同样的问题并找到了解决方案。如果在同一页面上有TextField和成像器选择器,请确保在选择图像时文本框未聚焦(光标应从TextField移开)。 在pickImage方法中执行类似FocusScope.of(context).requestFocus(new FocusNode());的操作。

本文链接:https://www.f2er.com/3112595.html

大家都在问