I have a StreamProvider here:
final secondTabProvider = StreamProvider((ref){
EmergencyContactsController contacts = EmergencyContactsController(currentUserID: ref.read(authProvider).currentUser!.uid);
return contacts.getUserEmergencyContacts();
});
And I call it in my build method like so:
_secondTab.when(
data: (data) {
if (!data.exists){
return Text("no data")
}
Map<String, dynamic doc = data.doc() as Map<String, dynamic>;
List conversations = doc['conversation'];
// Store the user profiles
List<EmergencyContactModel> users = [];
for (Map<String, dynamic> user in userConversations){
contacts.getContactInfo(
uid: user['userID']
).then((value){
if (value != null){
EmergencyContactModel contact = EmergencyContactModel.fromJson(value);
contact.messageID = value["id"] + ref.read(authProvider).currentUser!.uid;
users.add(contact);
}
});
}
return Listview.builder(
itemCount: users.length,
itemBuilder: (BuildContext context, int index) => Text(users[index]['name'])
);
},
error: (err, _){
return Text("Error")
},
loading: () => CircularProgressIndicator()
)
The contacts.getContactInfo() method is an async and I need it to execute before the loop continues to the next iteration, but it's not doing that. Any help would be largely appreciated.