title: Firebase: Iterate over map
body: <p>I got a collection called &quot;inventar&quot; which contains a doc with an auto generated value which contains a single map I want to iterate about.</p>
  <p>Note that the keys are going to vary, because the user is going to specify it.</p>
  <p>How can I iterate over this map so that I can output the key and value in my table cells listed below?</p>
  <p><a href="https://i.stack.imgur.com/Gm3a9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gm3a9.png" alt="enter image description here" /></a></p>
  <pre><code>new StreamBuilder&lt;QuerySnapshot&gt;(
                  stream: FirebaseFirestore.instance
                      .collection(&quot;inventar&quot;)
                      .where(&quot;verfallsdatum&quot;)
                      .snapshots(),
                  builder: (BuildContext context,
                      AsyncSnapshot&lt;QuerySnapshot&gt; snapshot) {
                    if (snapshot.hasError) {
                      return Text('Something went wrong');
                    }
  
                    if (snapshot.connectionState == ConnectionState.waiting) {
                      return Text(&quot;Loading&quot;);
                    }
  
                    return new Table(
                      children: [
                        new TableRow(children: [
                          new TableCell(child: new Text(&quot;Produkt&quot;)),
                          new TableCell(child: new Text(&quot;Verfallsdatum&quot;)),
                        ]),
  
                        // how to iterate here?
  
                          new TableRow(
                            children: [
                              new TableCell(
                                child: new Text(&quot;key&quot;),
                              ),
                              new TableCell(
                                child: new Text(&quot;value&quot;),
                              ),
                            ]
                          )
                      ]);
                  },
                )
  </code></pre>
  <p>Edit:
  I am trying to get this data out of my database since alomost one month! Which major mistake or misunderstanding do I have, that I am unable to query single document which contains a map and output it as table? Is this task so awefuly rough to perform or am I just dumb? :D</p>
  <p>Here is the recent attampt I did, but it says there is no method &quot;forEach&quot; for the type &quot;DocumentSnapshot&quot; even though I think I say this attampt in pretty much every tutorial. But mine aint work!</p>
  <pre><code>    var products = await db.collection(&quot;inventar&quot;).doc(&quot;vqQXArtqnFyAlkPC1PHr&quot;).get().then((snapshot) =&gt; {
    snapshot.forEach((doc) =&gt; {
  
    })
  });
  </code></pre>