如何更新 Flutter cloud_firestore 中的数组值?

mag*_*n94 9 dart flutter google-cloud-firestore

我有一个包含数组字段的文档。

如何更新阵列?

在 firebase 函数中,使用打字稿,我做了这样的事情:

admin.firestore()
    .collection('friendships')
    .doc(caller.data["uid"])
    .update({
        friends: admin.firestore.FieldValue
            .arrayUnion({
                          friendDisplayName: snapshot.data["friendDisplayName"],
                          friendUid: snapshot.ref
                       })
    })
Run Code Online (Sandbox Code Playgroud)

我找不到 Flutter 的任何替代方案.. 我该怎么办?

Har*_*ish 5

像这样的东西

firestore.instance.
    .collection('friendships')
    .document(caller.data["uid"])
    .updateData({
  friends: FieldValue.arrayUnion({
    friendDisplayName: snapshot.data["friendDisplayName"],
    friendUid: snapshot.ref
  })
});
Run Code Online (Sandbox Code Playgroud)