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 getData() function.
Here's my code
class DatabaseService {
final locationCollection = FirebaseFirestore.instance.collection("location");
Future<List<HomePageModel>> getData() async {
List<HomePageModel> listData = [];
await locationCollection.get().then((QuerySnapshot querySnapshot){
querySnapshot.docs.forEach((doc) {
HomePageModel(
docId: doc.id,
continent: doc['continent'],
name: doc['name']
);
});
});
print("this is listData $listData");
return listData;
}
}
This is what console looks like:
I/flutter ( 430): this is listData []
And this is the HomePageModel class
class HomePageModel {
String? name;
String? docId;
String? continent;
HomePageModel({this.docId, this.name, this.continent});
}
I dont know how do i put these document data models retrieved from Firestore in listData thats why in the console listData doesnt have any data.
Thank you :)