【发布时间】:2020-08-16 16:39:03
【问题描述】:
我一直想知道使用哪个来读取 FireStore 快照,因为我可以使用 fromSnapshot,因为 snapshot["fieldName"] 工作正常。
现在,我在 https://codelabs.developers.google.com/codelabs/flutter-firebase/#10 的 Google 代码实验室中找到了一个示例
这条路是确定的方法吗?例如fromSnapshot,然后使用fromMap 获取snapshot.data?如果我不使用 fromMap 怎么办?我失去了什么?然后,我也看到了 fromJson 而不是 fromMap...
class Record {
final String name;
final int votes;
final DocumentReference reference;
Record.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['name'] != null),
assert(map['votes'] != null),
name = map['name'],
votes = map['votes'];
Record.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference);
@override
String toString() => "Record<$name:$votes>";
}
【问题讨论】:
-
this.fromMap(... 现在产生错误:无法将参数类型 'Map
Function()' 分配给参数类型 'Map ' . - 'Map' 来自 'dart:core'。 : this.fromMap(snapshot.data, reference: snapshot.reference);
标签: flutter google-cloud-firestore