如何更改firebase颤振中数组字段的值?
我有一个数组,其中包含firestore中的图像URL列表。我想在用户单击删除按钮时删除特定索引的特定图像。这就是我的firebase图像阵列的外观,这是我尝试过的如何更改firebase颤振中数组字段的值?,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我有一个数组,其中包含firestore中的图像URL列表。我想在用户单击删除按钮时删除特定索引的特定图像。这就是我的firebase图像阵列的外观,这是我尝试过的 FirebaseFirestore .instance
FirebaseFirestore
.instance
.collection(
'adsPost')
.doc(widget.id)
.update({
'${images[_current]}':
''
}).whenComplete(() {
print(
'image removed from firestore');
});
您有两个选项,将其从应用程序的列表中删除,然后使用删除图像后列出的新修改内容更新firebase文档:
.update({"images": images.remove(images[_current])});
或将其从Firebase中删除:
.update({"images": FieldValue.arrayRemove([images[_current]])})