Deleting the Files

Learn how to delete files from Firebase Storage.

We'll cover the following...

Adding the delete functionality

Deleting files from Firebase Storage might be the easiest function so far. The delete() method is offered by Firebase Storage, and we can implement it in our code as follows:

Future<void> deleteAndRefreshList(Reference imageRef) async {
try {
await imageRef.delete();
print('File deleted successfully');
setState(() {
imageFiles = StorageController().referenceDirImage.listAll();
});
} catch (e) {
print('Error deleting file: $e');
}
}

  • Line 3: This deletes the image referenced by imageRef from Firebase Storage. The ...