小编Moh*_*ini的帖子

无法将“XFIle”类型的值分配给“文件”类型的变量错误

我正在使用 image_picker: ^0.8.4+4 ,但出现此错误。我能做些什么来使这段代码正确?

late File selectedImage;
bool _isLoading = false;
CrudMethods crudMethods = CrudMethods();

Future getImage() async {
var image = await ImagePicker().pickImage(source: ImageSource.gallery);

setState(() {
  selectedImage = image; //A value of type 'XFIle' can't be assigned to a variable of type 'File' error.
});
}

uploadBlog() async {
// ignore: unnecessary_null_comparison
if (selectedImage != null) {
  setState(() {
    _isLoading = true;
  });
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-dependencies flutter-layout imagepicker

5
推荐指数
3
解决办法
2万
查看次数