Program tries to process data which was not retrieved yet. I put plenty of displays to verify that this indeed happens.
This my code inside Stateless widget: ....
Print(“before calling getDocs()”)
getDocs(); // retrieves data from Firestore
Print(“after calling getDocs()”)
data retrieved by getDocs() function is processed ....
getDocs() is defined outside any class or Widget
void getDocs() async {
print("******inside getDocs() start*****************");
await FirebaseFirestore.instance.collection('Spanish').get().then((snapshot) {
print("********inside getDocs() 1");
....
print("******inside getDocs() end*****************");
And this is what I see on the log:
before calling getDocs()
******inside getDocs() start*****************
******inside getDocs() end*****************
after calling getDocs()
********inside getDocs() 1
The result is an error - program tries to process data which was not retrieved yet. The other display from getDocs() shows the data was received correctly. Question - how to prevent program to process data when the data is not available yet?