I got a nested query in an forEach loop which never gets executed. The first print statements does its work but the second is never called so I think there is some problem with async/await here. Can I use async/await in a forEach - loop?
final CollectionReference activityfeedRef =
Firestore.instance.collection("activityfeed");
someFunction() async {
QuerySnapshot user = await userRef
.document(locationId)
.collection('user')
.getDocuments();
user.documents.forEach((doc) async {
if (doc.exists) {
var userId = doc['uid'];
print("userId"); //This print statement works
//Following query probably never gets executed
QuerySnapshot activity = await
activityfeedRef
.document(userId)
.collection('items')
.where('type', isEqualTo: 'comment')
.where('locationId', isEqualTo: widget.locId)
.getDocuments();
print("DONE"); //The print statement does not work
activity.documents.forEach((item) {
if (item.exists) {
print("Exists");
} else {
print("Does not exist");
}
});
}
});
}
Anybody suggestions?