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
Flutter 使用firestore db实现颤振数据序列化和反序列化_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Flutter 使用firestore db实现颤振数据序列化和反序列化

Flutter 使用firestore db实现颤振数据序列化和反序列化,flutter,dart,google-cloud-firestore,Flutter,Dart,Google Cloud Firestore,我在《颤栗》中遇到了这个奇怪的错误。我使用的是自定义数据模型: class ScanData { final String userID; final String companyID; final String scanID; final String deviceID; final String model; final Map result; final DateTime dateTime; final GeoPoint geoPoint; ScanD

我在《颤栗》中遇到了这个奇怪的错误。我使用的是自定义数据模型:

class ScanData {
  final String userID;
  final String companyID;
  final String scanID;
  final String deviceID;
  final String model;
  final Map result;
  final DateTime dateTime;
  final GeoPoint geoPoint;

  ScanData(
      {this.userID,
      this.companyID,
      this.scanID,
      this.deviceID,
      this.model,
      this.result,
      this.geoPoint,
      this.dateTime});

  factory ScanData.fromMap(Map data) {
    return ScanData(
      userID: data['userID'] ?? '',
      companyID: data['companyID'] ?? '',
      scanID: data['scanID'] ?? '',
      deviceID: data['deviceID'] ?? '',
      model: data['model'] ?? '',
      result: data['result'] ?? {},
      dateTime: data['dateTime'] as DateTime ?? DateTime.now(),
      geoPoint: data['geoPoint'] as GeoPoint ?? ['77', '28'],
    );
  }
}
在集合类中创建了从firestore检索数据的方法:

class Collection<T> {
  final FirebaseFirestore _db = FirebaseFirestore.instance;
  final String path;
  CollectionReference ref;

  Collection({this.path}) {
    ref = _db.collection(path);
  }

  Future<List<T>> getData() async {
    var snapshots = await ref.get();
    return snapshots.docs
        .map((doc) => Global.models[T](doc.data) as T)
        .toList();
  }
}
错误(发生在全局fromMap中):

发生异常。 _TypeError(类型“()=>Map”不是类型“Map”的子类型) 我尝试在Scanda模型中加入以下内容

factory ScanData.fromMap(Map<String,dynamic> data) {...}
factory Scanda.fromMap(映射数据){…}
但这也带来了另一个错误:

Exception has occurred.
_TypeError (type '() => Map<String, dynamic>' is not a subtype of type 'Map<String, dynamic>')
发生异常。 _TypeError(类型“()=>Map”不是类型“Map”的子类型)
:|非常感谢任何提示。

在Collection类的getData()方法中,
doc.data
不是属性,它是一个方法,所以只需添加
()

我认为您需要从到JSON进行编码和解码。firestore里有个虫子。不确定这些方法是否有效。非常感谢,m8!
Exception has occurred.
_TypeError (type '() => Map<String, dynamic>' is not a subtype of type 'Map<dynamic, dynamic>')
factory ScanData.fromMap(Map<String,dynamic> data) {...}
Exception has occurred.
_TypeError (type '() => Map<String, dynamic>' is not a subtype of type 'Map<String, dynamic>')