【问题标题】:PickedFile' can't be assigned to the parameter type 'File' errorPickedFile' 不能分配给参数类型 'File' 错误
【发布时间】:2021-02-28 14:42:50
【问题描述】:

我正在尝试制作一个可以打开相机并拍照并使用颤振加载它的应用程序。首先我使用了pickImage,但我收到了这条消息 'pickImage' 已弃用,不应使用。改用 imagePicker.getImage() 方法..

所以我使用了 getImage 方法...

_openCamera(BuildContext context) async{
var picture =await ImagePicker().getImage(source: ImageSource.camera);
this.setState(() {
  imageFile= picture;
});

但是当我使用下面的代码时出现了这个错误 参数类型“PickedFile”不能分配给参数类型“文件”。

 if(imageFile==null){
  return Text("No selected Image");
}else{
  Image.file(imageFile,width: 400,height: 400);
}

请帮帮我。我是 Flutter 的新手

【问题讨论】:

    标签: flutter android-studio dart imagepicker


    【解决方案1】:

    PickedFile,即imagePicker返回的类型,是image_picker包特有的类型,因此与File不同。

    您可以执行以下操作将其转换为File

    Image.file(File(imageFile.path), width: 400, height: 400);
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2022-01-23
      • 2022-08-14
      • 2021-10-03
      • 2020-01-05
      相关资源
      最近更新 更多