【发布时间】:2019-11-10 22:42:38
【问题描述】:
Future<Null> pickImageFromGallery() async {
String path = (await getApplicationDocumentsDirectory()).path;
File imageExist = new File(path + '/image1.png');
if(await imageExist.exists()) {
imageExist.delete();
}
File imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
if(imageFile == null) return;
File newImage = await imageFile.copy('$path/image1.png');
setState(() {
this.categoryIcon = newImage;
});
}
我正在创建一个允许用户为项目选择图标的应用程序。我正在使用图像选择器来允许用户选择图像。当用户选择图像时,我想覆盖应用目录中的文件。
但是使用该代码,我每次选择新图像时都会得到相同的文件图像。图片好像不能换了。
【问题讨论】:
-
没关系。 stackoverflow.com/questions/50936168/… 。我已经得到了解决方案
标签: android image file flutter io