繁体   English   中英

flutter onClick 从 firebase 存储和 firestore 中删除图像

[英]flutter onClick delete image from firebase storage and firestore

我需要单击从 firebase 存储和 firestore 中删除图像 我编写了这段代码,仅从 firestore 中删除。

onLongPress: ()async{
  await FirebaseFirestore.instance.runTransaction((Transaction myTransaction) async {
    await myTransaction.delete(snapshot.data!.docs[index].reference);
  });
},

从代码中筛选

在此处输入图像描述

您可以使用 FirebaseStorage.instance.refFromURL(url).delete()

喜欢

onLongPress: ()async{
  await FirebaseFirestore.instance.runTransaction((Transaction 
 myTransaction) async {
    FirebaseStorage.instance.refFromURL(snapshot.data!.docs[index].get('url')).delete()
    await myTransaction.delete(snapshot.data!.docs[index].reference);
  });
},
 child: ListView.builder(
                          itemCount: snapshot.data?.docs.length,
                          itemBuilder: (context, index) {
                            DocumentSnapshot messages = snapshot
                                .data?.docs[index] as DocumentSnapshot<Object?>;
                            return ListTile(
                              subtitle: Text('From: ${messages['sender']}'),
                              title: Text('Text: ${messages['text']}'),
                              tileColor:
                                  selectedIndex == index ? Colors.blue : null,
                              onTap: () async {
                                setState(() {
                                  selectedIndex = index;
                                });

                                await FirebaseFirestore.instance.runTransaction(
                                    (Transaction myTransaction) async {
                                  await myTransaction.delete(snapshot
                                      .data!.docs[selectedIndex!].reference);
                                });
                              },
                            );
                          }));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM