我正在从https://pub.dev/packages/image_picker学习图像选择器,但是当我逐步使用方式时,我不明白为什么会出错。
这是问题:
首先,我声明一个File变量
File _imageFile ;
然后我在方法中使用它,
_getimg() async{
var _img = await ImagePicker(source: ImageSource.gallery);
setState(() {
_imageFile = _img ;
});
}
然后我收到此错误:
类型为'File的值(其中File在D:\ Flutter \ flutter \ bin \ cache \ pkg \ sky_engine \ lib \ io \ file.dart)'无法分配给'File类型的变量(其中File在D:\ Flutter \ flutter \ bin \ cache \ pkg \ sky_engine \ lib \ html \ html_dart2js.dart)'。
文件声明之间存在冲突。 html
程序包具有一个类File
的声明,而io
程序包具有另一个声明(相同的名称,不同的来源)。
实际上,使用html
用于Web,io
用于控制台,服务器或移动应用程序,因此请检查导入并根据正在处理的项目类型删除io
或html
。
另一种解决方案是这样定义您的导入:
import 'package:html/html.dart' as h; //"h" can change, is just an example
import 'dart:io' as i; //"i" also can be another char or word, is just an example
//And when you need to create a File,
//you can decide if you want to create
//an io File or an html File
main(){
i.File f1 = ...; //The io File, starting with "i."
h.File f2 = ...; //The html File, starting with "h."
}