title: How to convert a sub collection to list with flutter and firestore?
body: <p>I have an object Dish who containes a list of ingredients and I want to get them. How can I do?
  In Firebase, Dish is a Document and Ingredient is a sub collection. I tried this but it doesn't work.</p>
  
  <pre><code>class Dish{
  
    String name;
    DocumentReference reference;
    List&lt;Ingredient&gt; ingredients;
  
    Dish.fromMap(Map&lt;String, dynamic&gt; map, {this.reference}){
      this.name = map['name'];
  
      this
          .reference
          .collection("ingredients")
          .snapshots()
          .listen((QuerySnapshot snap) {
        final List&lt;DocumentSnapshot&gt; ingredientsDocuments = snap.documents;
        List&lt;Ingredient&gt; ing = [];
        for (var i = 0; i &lt; ingredientsDocuments.length; i++) {
          ing.add(Ingredient.fromSnapshot(ingredientsDocuments[i]));
        }
        this.ingredients = ing;
      });
    }
  
  
  
    Dish.fromSnapshot(DocumentSnapshot snapshot)
        : this.fromMap(snapshot.data, reference: snapshot.reference);
  
    @override
    String toString() =&gt; "Dish&lt;$String&gt;";
  
  }
  
  class Ingredient{
    final String name;
    final DocumentReference reference;
  
    Ingredient.fromMap(Map&lt;String, dynamic&gt; map, {this.reference})
        : assert(map['name'] != null),
          name = map['name'];
  
    Ingredient.fromSnapshot(DocumentSnapshot snapshot)
        : this.fromMap(snapshot.data, reference: snapshot.reference);
  
    @override
    String toString() =&gt; "Ingredient&lt;$String&gt;";
  }
  </code></pre>