相关疑难解决方法(0)

如何在Flutter中从Cloud Firestore加载数组和对象

我有一类具有几个嵌入式数组以及几个对象的类。我正在使用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)

flutter google-cloud-firestore

9
推荐指数
4
解决办法
1万
查看次数

标签 统计

flutter ×1

google-cloud-firestore ×1