I am trying to read data from firestore collection to get notification token and push it to a list and pass the list to SendtoDevice function to send push notification.
I am facing issue when using foreach function and push the data getting error "for each is not a valid function"
let tokenList = [];
const userNotificationTokenDocs = await db.collection("userToken").doc(userId).get()
.then(querySnapshot => {
querySnapshot.forEach((doc) => {
console.log(doc.data().Tokens);
tokenList.push(doc.data().Tokens);
});
return null;
});
**other option which i tried, with same error.**
userNotificationTokenDocs.forEach(function(docs){
console.log(docs.data());
if(docs.data() != null){
tokenList.push(docs.data().Token);
}
});
Please help me, I am stuck with this.
awaitandthenin the same statement. That doesn't make any sense - just use one or the other. You might want to take a moment to review how Futures work in dart.