Commit 336074abbaf50d5a485233c429de5d0acd1cb08e
1 parent
820997e6
feat:过渡页-绘本环节跨单元处理
Showing
1 changed file
with
28 additions
and
10 deletions
lib/pages/section/bloc/section_bloc.dart
| ... | ... | @@ -110,11 +110,12 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { |
| 110 | 110 | } |
| 111 | 111 | if (event.autoNextSection) { |
| 112 | 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 | 125 | emitter(CurrentPageIndexState()); |
| 125 | 126 | } |
| 126 | 127 | |
| 127 | - // 未锁定的页(单元)数 | |
| 128 | + ///未锁定的页(单元)数 | |
| 128 | 129 | int unlockPageCount() { |
| 129 | 130 | return _courseUnitEntity.courseUnitVOList |
| 130 | 131 | ?.indexWhereOrNull((element) => element.lock == true) ?? |
| 131 | 132 | 1; |
| 132 | 133 | } |
| 133 | 134 | |
| 135 | + ///当前页的课程详情 | |
| 134 | 136 | CourseUnitDetail getCourseUnitDetail({int? pageIndex}) { |
| 135 | 137 | return _courseUnitEntity.courseUnitVOList![pageIndex ?? _currentPage]; |
| 136 | 138 | } |
| ... | ... | @@ -176,7 +178,8 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { |
| 176 | 178 | return null; |
| 177 | 179 | } |
| 178 | 180 | |
| 179 | - CourseSectionEntity? getNextCourseSection(int courseLessonId) { | |
| 181 | + ///根据courseLessonId查找下一个courseSection | |
| 182 | + Future<CourseSectionEntity?> getNextCourseSection(int courseLessonId) async { | |
| 180 | 183 | final curCourseSectionEntity = findCourseSectionById(courseLessonId); |
| 181 | 184 | final curSectionSort = curCourseSectionEntity?.sortOrder ?? 0; |
| 182 | 185 | final nextCourseSectionEntity = findCourseSectionBySort(curSectionSort + 1); |
| ... | ... | @@ -189,9 +192,24 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { |
| 189 | 192 | final nextCourseUnitDetail = _courseUnitEntity.courseUnitVOList |
| 190 | 193 | ?.firstWhere((element) => element.sortOrder == (curCourseUnitDetail.sortOrder! + 1)); |
| 191 | 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 | 213 | } else { |
| 196 | 214 | ///最后一个unit了 |
| 197 | 215 | return null; | ... | ... |