Reputation: 345
List<dynamic> allDataList = [];
Future<void> compareUserBids() async {
final QuerySnapshot snapshot = await Firestore.instance
.collection("Pro-$productName-$productId")
.getDocuments();
List<DocumentSnapshot> templist;
templist = snapshot.documents;
allDataList = templist.map((DocumentSnapshot ds) {
return {ds.documentID: ds.data};
}).toList();
return allDataList;
}
@override
Widget build(BuildContext context) {
compareUserBids();
print(allDataList);
}
When i am tying to print this data it is printing the null values but after hot reload it is printing the values
Upvotes: 1
Views: 708
Reputation: 56
The reason you're getting an empty list is that you've not updated your widget after adding data into your global list. You should either add the data either inside setState or you can call setState once before returning your list.
setState((){
allDataList = templist.map((DocumentSnapshot ds) {
return {ds.documentID: ds.data};
},
).toList()
},
);
Upvotes: 4