我有一类具有几个嵌入式数组以及几个对象的类。我正在使用Flutter,无法弄清楚如何读写Cloud Firestore。
我可以读写默认类型的数据成员,例如String和Int。这是我试图用来从DocumentSnapshot实例化对象的构造函数:
class GameReview {
String name;
int howPopular;
List<String> reviewers;
}
class ItemCount {
int itemType;
int count;
ItemCount.fromMap(Map<dynamic, dynamic> data)
: itemType = data['itemType'],
count = data['count'];
}
class GameRecord {
// Header members
String documentID;
String name;
int creationTimestamp;
List<int> ratings = new List<int>();
List<String> players = new List<String>();
GameReview gameReview;
List<ItemCount> itemCounts = new List<ItemCount>();
GameRecord.fromSnapshot(DocumentSnapshot snapshot)
: documentID = snapshot.documentID,
name = snapshot['name'],
creationTimestamp = snapshot['creationTimestamp'],
ratings = snapshot['ratings'], // ERROR on run
players …Run Code Online (Sandbox Code Playgroud)