flutter-在ListView中进行API调用
我正在调用API,该API将返回项目列表(锻炼),并且项目将在listView中显示。但是,我还需要为ListView的每个项目致电另一个API,以获取该锻炼的分数(如果已经有分数),并根据其ID向每个锻炼显示分数。如何解决这种情况?我正在使用Bloc,这就是我如何进行锻炼的方式,
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));
}
某些锻炼可能还没有分数,在这种情况下,我在ListView中显示一个按钮来记录每个锻炼的分数。
我尝试了这样的事情:
final listResults = await Stream.fromIterable(listWods)
.asyncMap((wod) => WhiteboardService().getresult(wod.id))
.toList();
但是由于某些锻炼可能没有结果,因此显示出错误。
如何通过结果进行链接锻炼并在listView中显示?请感谢任何帮助指南。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,可以从循环中完成。您必须为包括锻炼ID的结果创建模型类。然后,您可以循环浏览它,并从锻炼清单中找到相关的锻炼,然后为其分配结果。
有一个例子希望它会有所帮助。
*虚拟模型类
*将结果分配给锻炼清单,
我认为如果您可以从后端做到这一点,它将比这种方法更有效。 (例如: - 在SQL中加入查询)
As I understand, it can be done from a loop. You have to create a model class for results that include the workout id. Then you can loop through it and find the relevant workout from the workout list and then assign the results for it.
there is an example hope it will help.
*dummy model classes
*assign results to workout list
I think if you can do this from the backend it will be more efficient than this approach. (eg:- join query in sql)