title: Flutter Firebase getting list of document
body: <p>When I want to get data as object list</p>
  <pre><code> onPressed: () {
       print(&quot;entered&quot;);
       ProductServices _productServives = ProductServices();
       Future&lt;List&lt;dynamic&gt;&gt; plist = _productServives.getProducts2();
       print(plist);
    },
  </code></pre>
  <pre><code>Future&lt;List&lt;dynamic&gt;&gt; getProducts2() async {
      CollectionReference ref = _firestore.collection('Products');
      List&lt;Product&gt; productsArray = [];
  
      ref.snapshots().forEach((element) {
        element.docs.forEach((value) {
          var p = Product.fromSnapshot(value);
          productsArray.add(p);
          print(&quot;size: &quot; + productsArray.length.toString());
        });
        // productsArray.add(element);
      });
      print(&quot;+ size: &quot; + productsArray.length.toString());
  
      return productsArray;
    }
  </code></pre>
  <p>It is not working as I want line by line.
  In for each putting element to the list and increasing the size but because of the working queue returned list is empty.</p>
  <p>How can I fix this issue and where can I study asynchronous operation.</p>
  <p>Output:</p>
  <pre><code>I/flutter (29128): entered
  I/flutter (29128): + size: 0
  I/flutter (29128): Instance of 'Future&lt;List&lt;dynamic&gt;&gt;'
  I/flutter (29128): size: 1
  I/flutter (29128): size: 2
  I/flutter (29128): size: 3
  </code></pre>