Hello I am doing parallel network calls in flutter using the following code.
List<dynamic> results = await Future.wait([
apiCall1(),
apiCall2(),
...more api calls
]);
I need to update the status of each api call. Is there a way to know which api call was successfully completed and update something the status.
If I used .then
in individual futures, the results list contains null.
void main() async {
Future<int> future1 = Future.delayed(Duration(seconds: 1)).then((value) => 1);
Future<int> future2 = Future.delayed(Duration(seconds: 2)).then((value) => 2);
List<dynamic> results = await Future.wait([
future1.then((value) {
print(value);
}),
future2.then((value) {
print(value);
})
]);
print(results);
}
1
2
[null, null]