Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何使用Flatter Firestore在阵列中存储地图数据_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Firebase 如何使用Flatter Firestore在阵列中存储地图数据

Firebase 如何使用Flatter Firestore在阵列中存储地图数据,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我尝试用flatter制作一个关于健康博客的应用程序。我想用包含地图数据的数组存储一些数据。虽然我可以在Firestore上手动执行此操作,但我在编码时遇到了一些错误 下面是我尝试向数组添加地图数据的代码 Future<bool> updateUserCases(String userId, Map newCase) async { await _firestoreDB.collection("users").doc(userId).update

我尝试用flatter制作一个关于健康博客的应用程序。我想用包含地图数据的数组存储一些数据。虽然我可以在Firestore上手动执行此操作,但我在编码时遇到了一些错误

下面是我尝试向数组添加地图数据的代码

    Future<bool> updateUserCases(String userId, Map newCase) async {
    await _firestoreDB.collection("users").doc(userId).update({
      "userCases" : FieldValue.arrayUnion([newCase])
    });
    return true;
  }
Future updateUserCases(字符串userId,Map newCase)异步{
等待_firestoreDB.collection(“users”).doc(userId)。更新({
“userCases”:FieldValue.arrayUnion([newCase])
});
返回true;
}
我可以将地图数据添加到Firestore,但当我尝试将其添加到数组时,会出现此错误

E/flatter(10661):[错误:flatter/lib/ui/ui\u dart\u state.cc(186)]未处理的异常:[cloud\u firestore/unknown]无效数据。FieldValue.serverTimestamp()只能与set()和update()一起使用

这是我的“案例模型”,我想添加到数组中

    class CaseModel {
  final String caseId;
  final String caseTitle;
  final String caseBody;
  final Map caseOwner;
  Timestamp caseDate;
  bool caseSolve;
  List<String> casePhotos;
  String caseTag;

  CaseModel(
      {@required this.caseOwner,
      this.caseId,
      this.caseTitle,
      this.caseBody,
      this.caseDate,
      this.caseTag});

  Map<String, dynamic> toMap() {
    return {
      "case_id": caseId,
      "case_title": caseTitle,
      "case_body": caseBody,
      "case_owner": caseOwner,
      "case_date": caseDate ?? FieldValue.serverTimestamp(),
      "case_solve": caseSolve,
      "case_photos": casePhotos,
      "case_tag": caseTag,
    };
  }
类案例模型{
最终串caseId;
最后的字符串标题;
最终管柱盒体;
最终地图案例所有者;
时间戳caseDate;
布尔案件解决;
列出个案照片;
字符串标记;
案例模型(
{@required this.caseOwner,
这个,凯西德,
这是我的名字,
这个案子的主体,
这个日期,
这是.caseTag});
映射toMap(){
返回{
“案例id”:案例id,
“案例标题”:案例标题,
“案例正文”:案例正文,
“案件所有人”:案件所有人,
“case_date”:caseDate??FieldValue.serverTimestamp(),
“案例解决”:案例解决,
“案例照片”:案例照片,
“案例标签”:案例标签,
};
}

如果有什么方法可以解决这个问题,你能帮忙吗?谢谢。

请告诉我们
newCase
的值。另外,你是否在这段代码中的任何地方使用了
serverTimestamp()
?问题已经如你所说得到了更新。顺便说一下,我使用了
serverTimestamp()
CaseModel
中,但当我将
newCase
设置到Firestore文档中时,它工作正常。