diff --git a/lib/pages/section/bloc/section_bloc.dart b/lib/pages/section/bloc/section_bloc.dart index 3e6ae2b..8f5c8e1 100644 --- a/lib/pages/section/bloc/section_bloc.dart +++ b/lib/pages/section/bloc/section_bloc.dart @@ -110,11 +110,12 @@ class SectionBloc extends Bloc { } if (event.autoNextSection) { final nextCourseSection = - getNextCourseSection(int.parse(event.courseLessonId)); - debugPrint("WQF nextCourseSection: $nextCourseSection"); - ///进入课堂 - add(RequestEnterClassEvent(nextCourseSection!.id.toString(), - nextCourseSection.courseType)); + await getNextCourseSection(int.parse(event.courseLessonId)); + if (nextCourseSection != null) { + ///进入课堂 + add(RequestEnterClassEvent(nextCourseSection.id.toString(), + nextCourseSection.courseType)); + } } } @@ -124,13 +125,14 @@ class SectionBloc extends Bloc { emitter(CurrentPageIndexState()); } - // 未锁定的页(单元)数 + ///未锁定的页(单元)数 int unlockPageCount() { return _courseUnitEntity.courseUnitVOList ?.indexWhereOrNull((element) => element.lock == true) ?? 1; } + ///当前页的课程详情 CourseUnitDetail getCourseUnitDetail({int? pageIndex}) { return _courseUnitEntity.courseUnitVOList![pageIndex ?? _currentPage]; } @@ -176,7 +178,8 @@ class SectionBloc extends Bloc { return null; } - CourseSectionEntity? getNextCourseSection(int courseLessonId) { + ///根据courseLessonId查找下一个courseSection + Future getNextCourseSection(int courseLessonId) async { final curCourseSectionEntity = findCourseSectionById(courseLessonId); final curSectionSort = curCourseSectionEntity?.sortOrder ?? 0; final nextCourseSectionEntity = findCourseSectionBySort(curSectionSort + 1); @@ -189,9 +192,24 @@ class SectionBloc extends Bloc { final nextCourseUnitDetail = _courseUnitEntity.courseUnitVOList ?.firstWhere((element) => element.sortOrder == (curCourseUnitDetail.sortOrder! + 1)); if (nextCourseUnitDetail != null) { - add(RequestDataEvent(nextCourseUnitDetail.id!)); - ///pageView翻页了,可能需要预加载 todo - return null; + final courseUnitId = nextCourseUnitDetail.id!; + try { + await loading(() async { + _courseSectionDatasMap[courseUnitId] = + await LessonDao.courseSection(courseUnitId: courseUnitId); + emit(LessonDataLoadState()); + }); + _pageController.nextPage( + duration: const Duration(milliseconds: 500), + curve: Curves.ease, + ); + return _courseSectionDatasMap[courseUnitId]!.first; + } catch (e) { + if (e is ApiException) { + showToast(e.message.toString()); + } + return null; + } } else { ///最后一个unit了 return null;