Reputation: 173
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;
});
}
I'm creating an application that allow user to choose an icon for item. I'm using Image Picker to allow user to choose an image. When the user choose an image, i want to overwrite the file in the app directory.
But with that code, i got the same File Image every time i choose a new image. It seems like the image can't be replaced.
Upvotes: 6
Views: 5549
Reputation: 81
import 'package:flutter/services.dart'
imageCache.clearLiveImages();
Add this incase it persists.
Upvotes: 1
Reputation: 145
You probably just need to clear the cache.
import 'package:flutter/services.dart';
imageCache.clear();
Upvotes: 10