【问题标题】:How to change the value of array field in firebase flutter?如何更改firebase颤振中数组字段的值?
【发布时间】:2021-05-05 15:30:26
【问题描述】:

我有一个数组,其中包含 Firestore 中的图像 URL 列表。当用户单击删除按钮时,我想删除某个索引的特定图像。这就是我的 firebase 图像数组的样子 这是我尝试过的

                                                 FirebaseFirestore
                                                            .instance
                                                            .collection(
                                                                'adsPost')
                                                            .doc(widget.id)
                                                            .update({
                                                          '${images[_current]}':
                                                              ''
                                                        }).whenComplete(() {
                                                          print(
                                                              'image removed from firestore');
                                                        });

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    您有两个选择,将其从应用程序的列表中删除,然后使用删除图像后列出的新修改更新您的 firebase 文档。:

    .update({"images": images.remove(images[_current])});
    

    或者从 Firebase 中删除它:

    .update({"images": FieldValue.arrayRemove([images[_current]])})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 2021-12-09
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多