I am calling an api, which will return a list of items (workouts), and items will be shown in a ListView. but I also need to call another api for each item of the ListView to fetch the score of that workout (if there is already a score) and show the score to each workout according to their id. How can I resolve this scenario.? I am using bloc and this is how I am fetching the workouts
Future<void> _onLoadingWod(
OnLoadingWodEvent event, Emitter<WhiteboardState> emit) async {
emit(state.copyWith(isWodLoading: true));
final listWods =
await WhiteboardService().getListWod(state.selectedDay.toString());
emit(state.copyWith(
isWodLoading: false, listWods: listWods));
}
some workouts may not have a score yet, in that case, I show in the listview a button to log a score for each workout.
I tried something like this:
final listResults = await Stream.fromIterable(listWods)
.asyncMap((wod) => WhiteboardService().getresult(wod.id))
.toList();
but since some workouts may not have result, is showing error.
how can a link workouts with results and show then in a listview? pls any help o guide is appreciated.