Commit 336074abbaf50d5a485233c429de5d0acd1cb08e

Authored by 吴启风
1 parent 820997e6

feat:过渡页-绘本环节跨单元处理

lib/pages/section/bloc/section_bloc.dart
@@ -110,11 +110,12 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { @@ -110,11 +110,12 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> {
110 } 110 }
111 if (event.autoNextSection) { 111 if (event.autoNextSection) {
112 final nextCourseSection = 112 final nextCourseSection =
113 - getNextCourseSection(int.parse(event.courseLessonId));  
114 - debugPrint("WQF nextCourseSection: $nextCourseSection");  
115 - ///进入课堂  
116 - add(RequestEnterClassEvent(nextCourseSection!.id.toString(),  
117 - nextCourseSection.courseType)); 113 + await getNextCourseSection(int.parse(event.courseLessonId));
  114 + if (nextCourseSection != null) {
  115 + ///进入课堂
  116 + add(RequestEnterClassEvent(nextCourseSection.id.toString(),
  117 + nextCourseSection.courseType));
  118 + }
118 } 119 }
119 } 120 }
120 121
@@ -124,13 +125,14 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { @@ -124,13 +125,14 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> {
124 emitter(CurrentPageIndexState()); 125 emitter(CurrentPageIndexState());
125 } 126 }
126 127
127 - // 未锁定的页(单元)数 128 + ///未锁定的页(单元)数
128 int unlockPageCount() { 129 int unlockPageCount() {
129 return _courseUnitEntity.courseUnitVOList 130 return _courseUnitEntity.courseUnitVOList
130 ?.indexWhereOrNull((element) => element.lock == true) ?? 131 ?.indexWhereOrNull((element) => element.lock == true) ??
131 1; 132 1;
132 } 133 }
133 134
  135 + ///当前页的课程详情
134 CourseUnitDetail getCourseUnitDetail({int? pageIndex}) { 136 CourseUnitDetail getCourseUnitDetail({int? pageIndex}) {
135 return _courseUnitEntity.courseUnitVOList![pageIndex ?? _currentPage]; 137 return _courseUnitEntity.courseUnitVOList![pageIndex ?? _currentPage];
136 } 138 }
@@ -176,7 +178,8 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { @@ -176,7 +178,8 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> {
176 return null; 178 return null;
177 } 179 }
178 180
179 - CourseSectionEntity? getNextCourseSection(int courseLessonId) { 181 + ///根据courseLessonId查找下一个courseSection
  182 + Future<CourseSectionEntity?> getNextCourseSection(int courseLessonId) async {
180 final curCourseSectionEntity = findCourseSectionById(courseLessonId); 183 final curCourseSectionEntity = findCourseSectionById(courseLessonId);
181 final curSectionSort = curCourseSectionEntity?.sortOrder ?? 0; 184 final curSectionSort = curCourseSectionEntity?.sortOrder ?? 0;
182 final nextCourseSectionEntity = findCourseSectionBySort(curSectionSort + 1); 185 final nextCourseSectionEntity = findCourseSectionBySort(curSectionSort + 1);
@@ -189,9 +192,24 @@ class SectionBloc extends Bloc&lt;SectionEvent, SectionState&gt; { @@ -189,9 +192,24 @@ class SectionBloc extends Bloc&lt;SectionEvent, SectionState&gt; {
189 final nextCourseUnitDetail = _courseUnitEntity.courseUnitVOList 192 final nextCourseUnitDetail = _courseUnitEntity.courseUnitVOList
190 ?.firstWhere((element) => element.sortOrder == (curCourseUnitDetail.sortOrder! + 1)); 193 ?.firstWhere((element) => element.sortOrder == (curCourseUnitDetail.sortOrder! + 1));
191 if (nextCourseUnitDetail != null) { 194 if (nextCourseUnitDetail != null) {
192 - add(RequestDataEvent(nextCourseUnitDetail.id!));  
193 - ///pageView翻页了,可能需要预加载 todo  
194 - return null; 195 + final courseUnitId = nextCourseUnitDetail.id!;
  196 + try {
  197 + await loading(() async {
  198 + _courseSectionDatasMap[courseUnitId] =
  199 + await LessonDao.courseSection(courseUnitId: courseUnitId);
  200 + emit(LessonDataLoadState());
  201 + });
  202 + _pageController.nextPage(
  203 + duration: const Duration(milliseconds: 500),
  204 + curve: Curves.ease,
  205 + );
  206 + return _courseSectionDatasMap[courseUnitId]!.first;
  207 + } catch (e) {
  208 + if (e is ApiException) {
  209 + showToast(e.message.toString());
  210 + }
  211 + return null;
  212 + }
195 } else { 213 } else {
196 ///最后一个unit了 214 ///最后一个unit了
197 return null; 215 return null;