首页 > 解决方案 > 参数类型“int”不能分配给参数类型“List”'。使用 FieldValue.arrayUnion Firestore Flutter 时出错

问题描述

我正在从 RTD 切换到 Firestore,所以我对新数据库非常陌生。我正在尝试使用将值添加到文档的字段(数组)ordersFieldValue.arrayUnion但我得到了The argument type 'int' can't be assigned to the parameter type 'List<dynamic>'.. 我究竟做错了什么?非常感谢。

// User collection
    _firestore
    .collection('Users')
    .doc(_firebaseAuth.currentUser.uid)
    .update({'orders': FieldValue.arrayUnion(order.orderId)});

标签: firebaseflutterdartgoogle-cloud-firestore

解决方案


arrayUnion将列表作为参数而不是 int,因此请尝试以下操作:

.update({'orders': FieldValue.arrayUnion([order.orderId])});

推荐阅读