0

我有 listview 并想使用 cubit 在每个 listview 中获取数据。但是目前我所有的列表视图项目都具有相同的内容,尽管它们正在访问不同的 API。我认为cubit会覆盖数据,但不知道如何解决。我的小部件调用了每个列表视图项:

Widget build(BuildContext context) {
   return BlocBuilder<PeriodCubit, PeriodState>(
    cubit: BlocProvider.of<PeriodCubit(context)..getPeriod(widget.activity.period, widget.activity.courseId),
    builder: (context, state) {
      if (state is PeriodLoaded) {
        //
      }
    }
}

这是我的腕尺码:

class PeriodCubit extends Cubit<PeriodState> {
    final AttendanceRepository _dailyRepository = new AttendanceRepository();
    PeriodCubit() : super(PeriodLoading());
    getPeriod(int period, int courseId) async {
      try {
         emit(PeriodLoading());
         final user = await _userRepository.getUser();
         final date = FormatDateTime.formatDateNumeric(DateTime.now());
         final attendanceDaily = await _dailyRepository.getAttendancebyPeriod(
          websiteId: user.websiteId, period: period, date: date, courseId: courseId);
         emit(PeriodLoaded(attendanceDaily));
       } catch (e) {
       emit(PeriodError(e));
    }
  }
4

0 回答 0