deleteAllLocalImages method
Deletes all local images referenced in a Quill document. it's not supported on web for now
Be careful, on desktop you should never delete user images. only if you are sure the image is saved in applicaton documents directory
on mobile the app is sandboxed so you can't delete user images because it will be a copy of the image for the app so you should be safe
This function removes local images from the file system that are referenced in the provided document.
document: The Quill document from which images will be deleted.
Throws an Exception if any errors occur during the deletion process.
Example usage:
try {
await deleteAllLocalImagesOfDocument(myQuillDocument);
} catch (e) {
print('Error deleting local images: $e');
}
Implementation
Future<void> deleteAllLocalImages() async {
_webIsNotSupported('deleteAllLocalImagesOfDocument');
final imagesPaths = getImagesPathsFromDocument(
onlyLocalImages: true,
);
for (final image in imagesPaths) {
final imageFile = File(image);
final fileExists = await imageFile.exists();
if (!fileExists) {
return;
}
final deletedFile = await imageFile.delete();
final deletedFileStillExists = await deletedFile.exists();
if (deletedFileStillExists) {
throw Exception(
'We have successfully deleted the file and it is still exists!!',
);
}
}
}