diff --git a/lib/pages/reading/reading_page.dart b/lib/pages/reading/reading_page.dart index 8e1c60a..a4a4f20 100644 --- a/lib/pages/reading/reading_page.dart +++ b/lib/pages/reading/reading_page.dart @@ -8,6 +8,7 @@ import 'package:wow_english/route/route.dart'; import '../../common/core/app_consts.dart'; import '../../common/core/user_util.dart'; +import '../../common/widgets/throttledGesture_gesture_detector.dart'; import '../../models/course_process_entity.dart'; import '../../utils/log_util.dart'; import 'bloc/reading_bloc.dart'; @@ -187,7 +188,8 @@ class _ReadingPage extends StatelessWidget { SizedBox( width: 10.w, ), - GestureDetector( + ThrottledGestureDetector( + throttleTime: 1000, onTap: () { if (bloc.isRecording) { bloc.add(XSVoiceStopEvent()); diff --git a/lib/pages/section/bloc/section_bloc.dart b/lib/pages/section/bloc/section_bloc.dart index 8f5c8e1..13c1361 100644 --- a/lib/pages/section/bloc/section_bloc.dart +++ b/lib/pages/section/bloc/section_bloc.dart @@ -37,14 +37,15 @@ class SectionBloc extends Bloc { ///courseUnitId与课程环节列表的映射 final Map?> _courseSectionDatasMap = {}; - Map?> get courseSectionDatasMap => _courseSectionDatasMap; + Map?> get courseSectionDatasMap => + _courseSectionDatasMap; CourseProcessEntity? _processEntity; CourseProcessEntity? get processEntity => _processEntity; - SectionBloc(this._courseUnitEntity, this._currentPage, - this._pageController, this._listController) + SectionBloc(this._courseUnitEntity, this._currentPage, this._pageController, + this._listController) : super(LessonInitial()) { on(_requestSectionsData); on(_requestEndClass); @@ -101,20 +102,18 @@ class SectionBloc extends Bloc { RequestEndClassEvent event, Emitter emitter) async { if (event.isCompleted) { await await ListenDao.endClass(event.courseLessonId, - currentStep: event.currentStep, - currentTime: event.currentTime); + currentStep: event.currentStep, currentTime: event.currentTime); } else { await await ListenDao.exitClass(event.courseLessonId, - currentStep: event.currentStep, - currentTime: event.currentTime); + currentStep: event.currentStep, currentTime: event.currentTime); } if (event.autoNextSection) { final nextCourseSection = - await getNextCourseSection(int.parse(event.courseLessonId)); + await getNextCourseSection(int.parse(event.courseLessonId), emitter); if (nextCourseSection != null) { ///进入课堂 - add(RequestEnterClassEvent(nextCourseSection.id.toString(), - nextCourseSection.courseType)); + add(RequestEnterClassEvent( + nextCourseSection.id.toString(), nextCourseSection.courseType)); } } } @@ -129,7 +128,8 @@ class SectionBloc extends Bloc { int unlockPageCount() { return _courseUnitEntity.courseUnitVOList ?.indexWhereOrNull((element) => element.lock == true) ?? - 1; + _courseUnitEntity.courseUnitVOList?.length ?? + 0; } ///当前页的课程详情 @@ -171,33 +171,40 @@ class SectionBloc extends Bloc { CourseUnitDetail? findCourseUnitDetailById(int courseLessonId) { final curCourseSectionEntity = findCourseSectionById(courseLessonId); if (curCourseSectionEntity != null) { - final curCourseUnitDetail = _courseUnitEntity.courseUnitVOList?.firstWhere((element) => - element.id == curCourseSectionEntity.courseUnitId); + final curCourseUnitDetail = _courseUnitEntity.courseUnitVOList + ?.firstWhere( + (element) => element.id == curCourseSectionEntity.courseUnitId); return curCourseUnitDetail; } return null; } ///根据courseLessonId查找下一个courseSection - Future getNextCourseSection(int courseLessonId) async { + Future getNextCourseSection( + int courseLessonId, Emitter emitter) async { final curCourseSectionEntity = findCourseSectionById(courseLessonId); final curSectionSort = curCourseSectionEntity?.sortOrder ?? 0; + + ///查找下一个section final nextCourseSectionEntity = findCourseSectionBySort(curSectionSort + 1); if (nextCourseSectionEntity != null) { return nextCourseSectionEntity; } else { - ///跨unit选lesson + ///section为空说明当前unit学完了,找下一个unit。(跨unit选lesson) + ///先根据courseLessonId找出当前的unit final curCourseUnitDetail = findCourseUnitDetailById(courseLessonId); if (curCourseUnitDetail != null) { + ///再根据当前unit找出下一个unit final nextCourseUnitDetail = _courseUnitEntity.courseUnitVOList - ?.firstWhere((element) => element.sortOrder == (curCourseUnitDetail.sortOrder! + 1)); + ?.firstWhere((element) => + element.sortOrder == (curCourseUnitDetail.sortOrder! + 1)); if (nextCourseUnitDetail != null) { final courseUnitId = nextCourseUnitDetail.id!; try { await loading(() async { _courseSectionDatasMap[courseUnitId] = - await LessonDao.courseSection(courseUnitId: courseUnitId); - emit(LessonDataLoadState()); + await LessonDao.courseSection(courseUnitId: courseUnitId); + emitter(LessonDataLoadState()); }); _pageController.nextPage( duration: const Duration(milliseconds: 500),