Reputation: 489
A.file
void drawMarkers(){
Marker marker = Marker();
marker.getListFromFirestore(users);
marker.getList(); <---- here2
}
void initState() {
// TODO: implement initState
drawMarkers();
super.initState();
}
B.file
class Marker{
List<Model> list;
void getListFromFirestore(List<dynamic> users) async {
list = await NetworkRepository.fetchListsFromAllUsers(users); <---- here1
}
List<Model> getList(){
return list;
}
}
In my code, value of list
is not empty (here1
). But at here2
the value is empty. what's wrong in my code?
Upvotes: 0
Views: 105
Reputation: 1385
You need to await
the call to getListFromFirestore
, since it is async
:
Future<void> drawMarkers() async{
Marker marker = Marker();
await marker.getListFromFirestore(users);
marker.getList(); <---- here2
}
Upvotes: 3