I'm creating a flutter app which hide your photos. I've used image_picker package to select image form gallery. And successfully copied the image to my application storage. Now I wanna delete original image from the gallery. How I can do that?
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
final pickedFile = await ImagePicker().getImage(source: ImageSource.gallery);
final File imageFile = File(pickedFile.path);
final fileName = DateTime.now().millisecondsSinceEpoch.toString();
final newPath = '${appDir.path}/$fileName.jpg';
final newFile = await File(pickedFile.path).copy(newPath);
await File(pickedFile.path).delete();
Image is not deleting as pickedFile.path is returning cache image path not the original path of selected image.
I've tried many code snippets from the ChatGPT and other blogs. Almost every solution was same but it didn't work in my case.
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
final pickedFile = await ImagePicker().getImage(source: ImageSource.gallery);
final File imageFile = File(pickedFile.path);
final fileName = DateTime.now().millisecondsSinceEpoch.toString();
final newPath = '${appDir.path}/$fileName.jpg';
final newFile = await File(pickedFile.path).copy(newPath);
await File(pickedFile.path).delete();
Above is the sample code. In this code:
await File(pickedFile.path).delete();
pickedFile.path
is not returning original path. It's the path of cached image which user has selected.
How I can delete selected images from gallery?