Commit 1ebed821195a57428c6b63d3bbd8c8ba07e00fe6
1 parent
ae77d87f
feat:修复所有unit解锁态下page页数
Showing
2 changed files
with
28 additions
and
19 deletions
lib/pages/reading/reading_page.dart
@@ -8,6 +8,7 @@ import 'package:wow_english/route/route.dart'; | @@ -8,6 +8,7 @@ import 'package:wow_english/route/route.dart'; | ||
8 | 8 | ||
9 | import '../../common/core/app_consts.dart'; | 9 | import '../../common/core/app_consts.dart'; |
10 | import '../../common/core/user_util.dart'; | 10 | import '../../common/core/user_util.dart'; |
11 | +import '../../common/widgets/throttledGesture_gesture_detector.dart'; | ||
11 | import '../../models/course_process_entity.dart'; | 12 | import '../../models/course_process_entity.dart'; |
12 | import '../../utils/log_util.dart'; | 13 | import '../../utils/log_util.dart'; |
13 | import 'bloc/reading_bloc.dart'; | 14 | import 'bloc/reading_bloc.dart'; |
@@ -187,7 +188,8 @@ class _ReadingPage extends StatelessWidget { | @@ -187,7 +188,8 @@ class _ReadingPage extends StatelessWidget { | ||
187 | SizedBox( | 188 | SizedBox( |
188 | width: 10.w, | 189 | width: 10.w, |
189 | ), | 190 | ), |
190 | - GestureDetector( | 191 | + ThrottledGestureDetector( |
192 | + throttleTime: 1000, | ||
191 | onTap: () { | 193 | onTap: () { |
192 | if (bloc.isRecording) { | 194 | if (bloc.isRecording) { |
193 | bloc.add(XSVoiceStopEvent()); | 195 | bloc.add(XSVoiceStopEvent()); |
lib/pages/section/bloc/section_bloc.dart
@@ -37,14 +37,15 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | @@ -37,14 +37,15 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | ||
37 | ///courseUnitId与课程环节列表的映射 | 37 | ///courseUnitId与课程环节列表的映射 |
38 | final Map<int, List<CourseSectionEntity>?> _courseSectionDatasMap = {}; | 38 | final Map<int, List<CourseSectionEntity>?> _courseSectionDatasMap = {}; |
39 | 39 | ||
40 | - Map<int, List<CourseSectionEntity>?> get courseSectionDatasMap => _courseSectionDatasMap; | 40 | + Map<int, List<CourseSectionEntity>?> get courseSectionDatasMap => |
41 | + _courseSectionDatasMap; | ||
41 | 42 | ||
42 | CourseProcessEntity? _processEntity; | 43 | CourseProcessEntity? _processEntity; |
43 | 44 | ||
44 | CourseProcessEntity? get processEntity => _processEntity; | 45 | CourseProcessEntity? get processEntity => _processEntity; |
45 | 46 | ||
46 | - SectionBloc(this._courseUnitEntity, this._currentPage, | ||
47 | - this._pageController, this._listController) | 47 | + SectionBloc(this._courseUnitEntity, this._currentPage, this._pageController, |
48 | + this._listController) | ||
48 | : super(LessonInitial()) { | 49 | : super(LessonInitial()) { |
49 | on<RequestDataEvent>(_requestSectionsData); | 50 | on<RequestDataEvent>(_requestSectionsData); |
50 | on<RequestEndClassEvent>(_requestEndClass); | 51 | on<RequestEndClassEvent>(_requestEndClass); |
@@ -101,20 +102,18 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | @@ -101,20 +102,18 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | ||
101 | RequestEndClassEvent event, Emitter<SectionState> emitter) async { | 102 | RequestEndClassEvent event, Emitter<SectionState> emitter) async { |
102 | if (event.isCompleted) { | 103 | if (event.isCompleted) { |
103 | await await ListenDao.endClass(event.courseLessonId, | 104 | await await ListenDao.endClass(event.courseLessonId, |
104 | - currentStep: event.currentStep, | ||
105 | - currentTime: event.currentTime); | 105 | + currentStep: event.currentStep, currentTime: event.currentTime); |
106 | } else { | 106 | } else { |
107 | await await ListenDao.exitClass(event.courseLessonId, | 107 | await await ListenDao.exitClass(event.courseLessonId, |
108 | - currentStep: event.currentStep, | ||
109 | - currentTime: event.currentTime); | 108 | + currentStep: event.currentStep, currentTime: event.currentTime); |
110 | } | 109 | } |
111 | if (event.autoNextSection) { | 110 | if (event.autoNextSection) { |
112 | final nextCourseSection = | 111 | final nextCourseSection = |
113 | - await getNextCourseSection(int.parse(event.courseLessonId)); | 112 | + await getNextCourseSection(int.parse(event.courseLessonId), emitter); |
114 | if (nextCourseSection != null) { | 113 | if (nextCourseSection != null) { |
115 | ///进入课堂 | 114 | ///进入课堂 |
116 | - add(RequestEnterClassEvent(nextCourseSection.id.toString(), | ||
117 | - nextCourseSection.courseType)); | 115 | + add(RequestEnterClassEvent( |
116 | + nextCourseSection.id.toString(), nextCourseSection.courseType)); | ||
118 | } | 117 | } |
119 | } | 118 | } |
120 | } | 119 | } |
@@ -129,7 +128,8 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | @@ -129,7 +128,8 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | ||
129 | int unlockPageCount() { | 128 | int unlockPageCount() { |
130 | return _courseUnitEntity.courseUnitVOList | 129 | return _courseUnitEntity.courseUnitVOList |
131 | ?.indexWhereOrNull((element) => element.lock == true) ?? | 130 | ?.indexWhereOrNull((element) => element.lock == true) ?? |
132 | - 1; | 131 | + _courseUnitEntity.courseUnitVOList?.length ?? |
132 | + 0; | ||
133 | } | 133 | } |
134 | 134 | ||
135 | ///当前页的课程详情 | 135 | ///当前页的课程详情 |
@@ -171,33 +171,40 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | @@ -171,33 +171,40 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | ||
171 | CourseUnitDetail? findCourseUnitDetailById(int courseLessonId) { | 171 | CourseUnitDetail? findCourseUnitDetailById(int courseLessonId) { |
172 | final curCourseSectionEntity = findCourseSectionById(courseLessonId); | 172 | final curCourseSectionEntity = findCourseSectionById(courseLessonId); |
173 | if (curCourseSectionEntity != null) { | 173 | if (curCourseSectionEntity != null) { |
174 | - final curCourseUnitDetail = _courseUnitEntity.courseUnitVOList?.firstWhere((element) => | ||
175 | - element.id == curCourseSectionEntity.courseUnitId); | 174 | + final curCourseUnitDetail = _courseUnitEntity.courseUnitVOList |
175 | + ?.firstWhere( | ||
176 | + (element) => element.id == curCourseSectionEntity.courseUnitId); | ||
176 | return curCourseUnitDetail; | 177 | return curCourseUnitDetail; |
177 | } | 178 | } |
178 | return null; | 179 | return null; |
179 | } | 180 | } |
180 | 181 | ||
181 | ///根据courseLessonId查找下一个courseSection | 182 | ///根据courseLessonId查找下一个courseSection |
182 | - Future<CourseSectionEntity?> getNextCourseSection(int courseLessonId) async { | 183 | + Future<CourseSectionEntity?> getNextCourseSection( |
184 | + int courseLessonId, Emitter<SectionState> emitter) async { | ||
183 | final curCourseSectionEntity = findCourseSectionById(courseLessonId); | 185 | final curCourseSectionEntity = findCourseSectionById(courseLessonId); |
184 | final curSectionSort = curCourseSectionEntity?.sortOrder ?? 0; | 186 | final curSectionSort = curCourseSectionEntity?.sortOrder ?? 0; |
187 | + | ||
188 | + ///查找下一个section | ||
185 | final nextCourseSectionEntity = findCourseSectionBySort(curSectionSort + 1); | 189 | final nextCourseSectionEntity = findCourseSectionBySort(curSectionSort + 1); |
186 | if (nextCourseSectionEntity != null) { | 190 | if (nextCourseSectionEntity != null) { |
187 | return nextCourseSectionEntity; | 191 | return nextCourseSectionEntity; |
188 | } else { | 192 | } else { |
189 | - ///跨unit选lesson | 193 | + ///section为空说明当前unit学完了,找下一个unit。(跨unit选lesson) |
194 | + ///先根据courseLessonId找出当前的unit | ||
190 | final curCourseUnitDetail = findCourseUnitDetailById(courseLessonId); | 195 | final curCourseUnitDetail = findCourseUnitDetailById(courseLessonId); |
191 | if (curCourseUnitDetail != null) { | 196 | if (curCourseUnitDetail != null) { |
197 | + ///再根据当前unit找出下一个unit | ||
192 | final nextCourseUnitDetail = _courseUnitEntity.courseUnitVOList | 198 | final nextCourseUnitDetail = _courseUnitEntity.courseUnitVOList |
193 | - ?.firstWhere((element) => element.sortOrder == (curCourseUnitDetail.sortOrder! + 1)); | 199 | + ?.firstWhere((element) => |
200 | + element.sortOrder == (curCourseUnitDetail.sortOrder! + 1)); | ||
194 | if (nextCourseUnitDetail != null) { | 201 | if (nextCourseUnitDetail != null) { |
195 | final courseUnitId = nextCourseUnitDetail.id!; | 202 | final courseUnitId = nextCourseUnitDetail.id!; |
196 | try { | 203 | try { |
197 | await loading(() async { | 204 | await loading(() async { |
198 | _courseSectionDatasMap[courseUnitId] = | 205 | _courseSectionDatasMap[courseUnitId] = |
199 | - await LessonDao.courseSection(courseUnitId: courseUnitId); | ||
200 | - emit(LessonDataLoadState()); | 206 | + await LessonDao.courseSection(courseUnitId: courseUnitId); |
207 | + emitter(LessonDataLoadState()); | ||
201 | }); | 208 | }); |
202 | _pageController.nextPage( | 209 | _pageController.nextPage( |
203 | duration: const Duration(milliseconds: 500), | 210 | duration: const Duration(milliseconds: 500), |