I am trying to loop through a List
to add each item to a google firestore doc
. However, the problem I am facing is that ONLY the last item in the List
is added to the doc.
Note: The line print("=== $i POST SUCCESSFULLY ADDED ====")
prints incremental for 5 times as expected
QUESTION: How can I get this loop to add all items to the firestore doc?
void addPost() {
DocumentReference documentReferencer = _firestore.collection('posts').doc();
var i = 0;
while (i < 5) {
documentReferencer.set(postsData[i]);
print("=== $i POST SUCCESSFULLY ADDED ===="); //PRINTS 5 TIMES
i++;
}
}