Reputation: 466
void initState() {
// TODO: implement initState
super.initState();
getusers().then((dataf){
snapshots=dataf.documents[1];// In here
});
}
final db=Firestore.instance;
DocumentSnapshot snapshots;
Future<QuerySnapshot> getusers(){
return db.collection("Users").document(widget.userid).collection("UsersJoined").getDocuments();
}
I want to get all the documents and fields inside documents without referring to their index. Is it possible by a loop or something to loop through the whole documents and get all their fields
Upvotes: 0
Views: 47
Reputation: 598817
To loop over the documents in the QuerySnapshot
:
getusers().then((dataf){
for (var userDoc in dataf.documents) {
print(userDoc["name"] // get the value of one field
var data = userDoc.data // get all data as a Map<String, Object>
})
});
Upvotes: 1