sometimes I upload images from my application to firebase storage and I put the URLS in firebase firestore and sometimes I put the URLS manually from random links in firebase firestore that's its not in my storage so when I want to Delete the item in firestore its only deleted if the images in my storage
deleteItem(id) async {
await FirebaseFirestore.instance.collection('sss').doc(id).delete();
setState(() {});
}
deleteimage(url) async {
await FirebaseStorage.instance.refFromURL(url).delete();
setState(() {});
}
Future<void> deletefun(images) async {
for (int i = 0; i < images.length; i++) {
var imageUrl = await deleteimage(images[i]);
}
}
and the code of button to delete
ElevatedButton(
onPressed: () async {
if (data['imgurl'].isNotEmpty) {
await deletefun(
data['imgurl']); }
await deleteItem(data.id);
},
child: const Text('delete'),
),}