【问题标题】:Image picker scanned to null flutter图像选择器扫描到零颤动
【发布时间】:2021-12-02 17:51:31
【问题描述】:

文件 _image; 最终选择器 = ImagePicker();

Future getImage() async {
  final pickedFile = await picker.getImage(source: ImageSource.camera);

  setState(() {
    if (pickedFile != null) {
      _image = File(pickedFile.path);
    } else {
      print('No image selected.');
    }
  });
}

输出:

D/MediaScannerConnection(16161):扫描 /storage/emulated/0/Android/data/com.xxxx.xxxx/files/Pictures/9d9ed6a1-292c-428a-bf24-38ea1a58742c6940060118053310767.jpg 为空

【问题讨论】:

    标签: flutter dart imagepicker


    【解决方案1】:

    试试这个:

    PickedFile pickedFile = await picker.getImage(source: ImageSource.camera);
    
    if (pickedFile == null) {
      return null;
    }
    
    Directory appDirectory = await getApplicationDocumentsDirectory();
    File newImage = File(appDirectory.path + 'fileName');
    newImage.writeAsBytes(File(pickedFile.path).readAsBytesSync());
    
    setState(() {
      _image = newImage;
      print(newImage.path + ' test');
    });
    

    【讨论】:

    • 嗨,我试过了。它仍然将图像扫描为空。请。任何想法为什么会这样?
    【解决方案2】:

    有时会出现此错误,因为您需要清理构建文件夹。尝试执行flutter clean 并再次重建。

    【讨论】:

    • 嗨,我试过了,但没有用。拜托,你能帮忙提出其他建议吗?
    猜你喜欢
    • 1970-01-01
    • 2021-12-25
    • 2020-12-13
    • 2020-01-22
    • 1970-01-01
    • 2021-02-08
    • 2021-06-08
    • 2021-01-30
    • 1970-01-01
    相关资源
    最近更新 更多