title: How to convert Firestore document data into a Class
body: <p>In Firestore, theres some documents with fields like 'name' , 'continent' etc with their string values. Im using FutureBuilder in the main UI code, and calling the <code>getData()</code> function.</p>
  <p>Here's my code</p>
  <pre><code>class DatabaseService {
  
    final locationCollection = FirebaseFirestore.instance.collection(&quot;location&quot;);
  
    Future&lt;List&lt;HomePageModel&gt;&gt; getData() async {
  
      List&lt;HomePageModel&gt; listData = [];
  
      await locationCollection.get().then((QuerySnapshot querySnapshot){
        querySnapshot.docs.forEach((doc) {
          HomePageModel(
            docId: doc.id,
            continent: doc['continent'],
            name: doc['name']
          );
        });
      });
      print(&quot;this is listData $listData&quot;);
      return listData;
    }
  
  }
  </code></pre>
  <p>This is what console looks like:</p>
  <p><code>I/flutter (  430): this is listData []</code></p>
  <p>And this is the HomePageModel class</p>
  <pre><code>class HomePageModel {
  
    String? name;
    String? docId;
    String? continent;
    HomePageModel({this.docId, this.name, this.continent});
  }
  </code></pre>
  <p>I dont know how do i put these document data models retrieved from Firestore in <code>listData</code> thats why in the console <code>listData</code> doesnt have any data.
  Thank you :)</p>