title: Flutter wait for Firestore to complete
body: <p>I am using flutter with firebase to create an app. The function below gets some data from my firebase database, but the problem is that it takes too long to get the data. How can make sure the app waits for the firebase getting data to finish first before proceeding?</p>
  
  <p>I would like to do something like an await, but I don't know if I can do:</p>
  
  <pre><code>await Firestore.instance...
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>  void getData() {
  
      Firestore.instance
          .collection('collection')
          .document('document')
          .get()
          .then((DocumentSnapshot ds) {
  
            var count = ds.data.length;
            for(var i = 0; i &lt; count; i ++){
              Firestore.instance
                  .collection('collection')
                  .document('document')
                  .get()
                  .then((DocumentSnapshot dss) {
                  // do something
  
              });
            }
      });
    }
  </code></pre>