title: Waiting for result of Future<DocumentSnapshot> in Flutter Firestore
body: <p>I have a cloud FireStore database with 2 fields.</p>
  
  <ul>
  <li>imageUrl (url of a remote file)</li>
  <li>user (reference field of a document in users collection)</li>
  </ul>
  
  <p>Below is how I get the documents from the images collection. </p>
  
  <pre><code>    class ImagePost {
  
        final String imageUrl;
  
        final User user;
  
        const ImagePost(
            {this.imageUrl,
            this.user});
  
        factory ImagePost.fromDocument(DocumentSnapshot document) {
          User userInfo;
  
          DocumentReference userReference = document['user'];
          Future&lt;DocumentSnapshot&gt; userRef = userReference.get();
  
         userRef.then((document) {
            userInfo = User.fromJSON(document.data);
          });
  
          ImagePost post = new ImagePost(
            imageUrl: document['imageUrl'],
            user: userInfo // ==&gt; always null while returning
          );
  
          return post;
        }
      }
  </code></pre>
  
  <p>When getting the reference user document, the <code>post</code> object always contains null value for user field. I expect the user object to be populated.</p>
  
  <p>But the user value is retrieved late and not returned along with the post object.</p>
  
  <p>How can I ensure that user value is retrieve before returning the post value?</p>