Flutter图像选择器未提供图像路径

时间:2020-07-13 13:35:05

标签: flutter

我正在尝试使用图像选择器在抖动中使用相机获取图像,但出现错误

          lib/Screen/AllDocuments.dart:15:3: Error: 'File' isn't a type.
          File _image;

我也尝试过投放,但仍然无法正常工作

       File _image;
   final picker = ImagePicker();

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

setState(() {
    _image = File(pickedFile);
  });
}

如何解决此错误

1 个答案:

答案 0 :(得分:2)

您必须在.path上调用pickedFile方法。 在此处查看此文档=> Image Picker

使用此:

 File _image;
   final picker = ImagePicker();

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

setState(() {
    _image = File(pickedFile.path);
  });
}