title: How do you load array and object from Cloud Firestore in Flutter
body: <p>I have a class that has several embedded arrays as well as a couple of objects. I'm using Flutter and can't figure out how to read/write to Cloud Firestore.</p>
  <p>I can read/write data members that are default types like String and Int. Here is the constructor I'm trying to use to instantiate an object from a DocumentSnapshot:</p>
  <pre><code> class GameReview {
     String name;
     int howPopular;
     List&lt;String&gt; reviewers;
   }
  
   class ItemCount {
     int itemType;
     int count;
  
     ItemCount.fromMap(Map&lt;dynamic, dynamic&gt; data)
         : itemType = data['itemType'],
           count = data['count'];
   }
  
   class GameRecord {
     // Header members
     String documentID;
     String name;
     int creationTimestamp;
     List&lt;int&gt; ratings = new List&lt;int&gt;();
     List&lt;String&gt; players = new List&lt;String&gt;();
     GameReview gameReview;
     List&lt;ItemCount&gt; itemCounts = new List&lt;ItemCount&gt;();
  
     GameRecord.fromSnapshot(DocumentSnapshot snapshot)
         : documentID = snapshot.documentID,
           name = snapshot['name'],
           creationTimestamp = snapshot['creationTimestamp'],
           ratings = snapshot['ratings'], // ERROR on run
           players = snapshot['players'], // ERROR on run
           gameReview = snapshot['gameReview']; // ERROR on run
           itemCount = ????
   }
  </code></pre>
  <p>It works until I add the last 3 members (ratings, players and gameReview). This should be obvious but none the less, it eludes me.</p>
  <p>Help!</p>
  <p>UPDATE:
  Here is a sample of the document stored in Cloud Firestore. This is stored in a single document. In other words, I'm not using sub-collections for the embedded objects. I put it into a JSON format for clarity. I hope this helps.</p>
  <pre><code> {
     &quot;documentID&quot;: &quot;asd8didjeurkff3&quot;,
     &quot;name&quot;: &quot;My Game Record&quot;,
     &quot;creationTimestamp&quot;: 1235434,
     &quot;ratings&quot;: [
       4,
       2012,
       4
     ],
     &quot;players&quot;: [
       &quot;Fred&quot;,
       &quot;Sue&quot;,
       &quot;John&quot;
     ],
     &quot;gameReview&quot;: {
       &quot;name&quot;: &quot;Review 1&quot;,
       &quot;howPopular&quot;: 5,
       &quot;reviewers&quot;: [
         &quot;Bob&quot;,
         &quot;Hanna&quot;,
         &quot;George&quot;
       ]
     },
    &quot;itemCounts&quot;: [
       {
         &quot;itemType&quot;: 2,
         &quot;count&quot;: 3
       },
       {
         &quot;itemType&quot;: 1,
         &quot;count&quot;: 2
       }
     ]
   }
  </code></pre>
  <p>UPDATE 2:
  I didn't put in the whole class definition because I thought it would be obvious to me how to do the rest but alas that was not the case.</p>
  <p>I have a list of objects that I want to load.vbandrade's answer is BANG on but I can't quite figure out how I'm supposed to create the list of objects.  List.from(...) is looking for an iterator, not a created class. I'm sure it's some variation of creating a new object and then adding it to a list but I'm a little confused. (see edits in class above, specifically, the &quot;itemCounts&quot; member.</p>