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;
});
}
Run Code Online (Sandbox Code Playgroud)
我正在创建一个允许用户为项目选择图标的应用程序。我正在使用图像选择器来允许用户选择图像。当用户选择图像时,我想覆盖应用程序目录中的文件。
但是使用该代码,每次选择新图像时我都会得到相同的文件图像。好像换不了图