有时我上传图像从我的应用程序到firebase存储,我把URL在firebase firestore,有时我把URL手动从随机链接在firebase firestore,这是它不在我的存储,所以当我想删除项目在firestore它只删除,如果图像在我的存储
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]);
}
}
和要删除按钮的代码
ElevatedButton(
onPressed: () async {
if (data['imgurl'].isNotEmpty) {
await deletefun(
data['imgurl']); }
await deleteItem(data.id);
},
child: const Text('delete'),
),}
1条答案
按热度按时间cs7cruho1#