From 820997e60600aa3f953e49bab5b06ea4c6ebf9ad Mon Sep 17 00:00:00 2001 From: wuqifeng <540416539@qq.com> Date: Wed, 15 May 2024 01:19:21 +0800 Subject: [PATCH] feat:过渡页-绘本环节 --- lib/pages/reading/bloc/reading_bloc.dart | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- lib/pages/reading/bloc/reading_event.dart | 2 +- lib/pages/reading/bloc/reading_state.dart | 2 +- lib/pages/reading/reading_page.dart | 5 +++-- lib/pages/section/bloc/section_bloc.dart | 1 + 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/lib/pages/reading/bloc/reading_bloc.dart b/lib/pages/reading/bloc/reading_bloc.dart index 6dc05d8..3012b82 100644 --- a/lib/pages/reading/bloc/reading_bloc.dart +++ b/lib/pages/reading/bloc/reading_bloc.dart @@ -6,11 +6,15 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart'; +import 'package:wow_english/pages/section/subsection/base_section/bloc.dart'; +import 'package:wow_english/pages/section/subsection/base_section/event.dart'; +import 'package:wow_english/pages/section/subsection/base_section/state.dart'; import '../../../common/core/user_util.dart'; import '../../../common/request/dao/listen_dao.dart'; import '../../../common/request/exception.dart'; import '../../../models/course_process_entity.dart'; +import '../../../route/route.dart'; import '../../../utils/loading.dart'; import '../../../utils/log_util.dart'; @@ -33,7 +37,8 @@ enum VoicePlayState { stop } -class ReadingPageBloc extends Bloc { +class ReadingPageBloc + extends BaseSectionBloc { final PageController pageController; final String courseLessonId; @@ -211,7 +216,7 @@ class ReadingPageBloc extends Bloc { } ///播放原音音频 - Future _playOriginalAudioInner(String? audioUrl) async { + void _playOriginalAudioInner(String? audioUrl) async { if (_isRecordAudioPlaying) { _isRecordAudioPlaying = false; } @@ -219,7 +224,7 @@ class ReadingPageBloc extends Bloc { "_playOriginalAudio _isRecordAudioPlaying=$_isRecordAudioPlaying _isOriginAudioPlaying=$_isOriginAudioPlaying url=$audioUrl"); if (_isOriginAudioPlaying) { _isOriginAudioPlaying = false; - await audioPlayer.stop(); + audioPlayer.stop(); } else { _isOriginAudioPlaying = true; audioUrl ??= currentPageData()?.audioUrl ?? ''; @@ -265,8 +270,17 @@ class ReadingPageBloc extends Bloc { } void nextPage() { - if (_currentPage >= dataCount() - 1) { - ///todo 最后一页了 + if (currentPage >= dataCount()) { + sectionComplete(() { + popPage(data: { + 'currentStep': currentPage, + 'courseLessonId': courseLessonId, + 'isCompleted': true, + 'nextSection': true + }); + }, againSectionTap: () { + pageController.jumpToPage(0); + }); } else { _currentPage += 1; pageController.nextPage( @@ -291,14 +305,14 @@ class ReadingPageBloc extends Bloc { void startRecord(String content) async { // 调用封装好的权限检查和请求方法 - bool result = await permissionCheckAndRequest( - context, - Permission.microphone, - "录音" - ); + bool result = + await permissionCheckAndRequest(context, Permission.microphone, "录音"); if (result) { - methodChannel.invokeMethod( - 'startVoice', {'word': content, 'type': '0', 'userId': UserUtil.getUser()?.id.toString()}); + methodChannel.invokeMethod('startVoice', { + 'word': content, + 'type': '0', + 'userId': UserUtil.getUser()?.id.toString() + }); } } @@ -313,7 +327,20 @@ class ReadingPageBloc extends Bloc { currentPageData()?.recordScore = overall; currentPageData()?.recordUrl = args['audioUrl'] + '.mp3'; ///完成录音后紧接着播放录音 - _playRecordAudioInner(); + await _playRecordAudioInner(); + if (isLastPage()) { + sectionComplete(() { + popPage(data: { + 'currentStep': currentPage, + 'courseLessonId': courseLessonId, + 'isCompleted': true, + 'nextSection': true + }); + }, againSectionTap: () { + _resetLocalResult(); + pageController.jumpToPage(0); + }); + } // emitter(FeedbackState()); } @@ -338,8 +365,11 @@ class ReadingPageBloc extends Bloc { nextPage(); } - Log.d("_onAudioPlayComplete _isOriginAudioPlaying=$_isOriginAudioPlaying _voicePlayState=$_voicePlayState recordUrl=${currentPageData()?.recordUrl?.isNotEmpty}"); - if (_isOriginAudioPlaying && _voicePlayState == VoicePlayState.completed && currentPageData()?.recordUrl?.isNotEmpty != true) { + Log.d( + "_onAudioPlayComplete _isOriginAudioPlaying=$_isOriginAudioPlaying _voicePlayState=$_voicePlayState recordUrl=${currentPageData()?.recordUrl?.isNotEmpty}"); + if (_isOriginAudioPlaying && + _voicePlayState == VoicePlayState.completed && + currentPageData()?.recordUrl?.isNotEmpty != true) { ///如果刚刚完成原音播放&&录音为空,则开始录音 startRecord(currentPageData()?.word ?? ''); } @@ -354,11 +384,21 @@ class ReadingPageBloc extends Bloc { _isRecordAudioPlaying = false; } - void _onVoiceXsStateChange( - OnXSVoiceStateChangeEvent event, - Emitter emitter - ) async { + void _onVoiceXsStateChange(OnXSVoiceStateChangeEvent event, + Emitter emitter) async { emitter(XSVoiceTestState()); } -} + ///是否是最后一页 + bool isLastPage() { + return currentPage == dataCount(); + } + + ///重置数据 + void _resetLocalResult() { + _entity?.readings?.forEach((element) { + element.recordScore = null; + element.recordUrl = null; + }); + } +} diff --git a/lib/pages/reading/bloc/reading_event.dart b/lib/pages/reading/bloc/reading_event.dart index ccebd9a..9d4ae4d 100644 --- a/lib/pages/reading/bloc/reading_event.dart +++ b/lib/pages/reading/bloc/reading_event.dart @@ -1,7 +1,7 @@ part of 'reading_bloc.dart'; @immutable -abstract class ReadingPageEvent {} +abstract class ReadingPageEvent extends BaseSectionEvent {} ///页面初始化 class InitBlocEvent extends ReadingPageEvent {} diff --git a/lib/pages/reading/bloc/reading_state.dart b/lib/pages/reading/bloc/reading_state.dart index dee9c28..d71ef2a 100644 --- a/lib/pages/reading/bloc/reading_state.dart +++ b/lib/pages/reading/bloc/reading_state.dart @@ -1,7 +1,7 @@ part of 'reading_bloc.dart'; @immutable -abstract class ReadingPageState {} +abstract class ReadingPageState extends BaseSectionState {} class ReadingPageInitial extends ReadingPageState {} diff --git a/lib/pages/reading/reading_page.dart b/lib/pages/reading/reading_page.dart index fcd0b55..5947b0d 100644 --- a/lib/pages/reading/reading_page.dart +++ b/lib/pages/reading/reading_page.dart @@ -88,8 +88,9 @@ class _ReadingPage extends StatelessWidget { onPressed: () { popPage( data:{ - 'currentStep':bloc.currentPage.toString(), - 'courseLessonId':bloc.courseLessonId + 'currentStep':bloc.currentPage, + 'courseLessonId':bloc.courseLessonId, + 'isCompleted':bloc.isLastPage(), } ); }, diff --git a/lib/pages/section/bloc/section_bloc.dart b/lib/pages/section/bloc/section_bloc.dart index 05f690b..3e6ae2b 100644 --- a/lib/pages/section/bloc/section_bloc.dart +++ b/lib/pages/section/bloc/section_bloc.dart @@ -111,6 +111,7 @@ 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)); -- libgit2 0.22.2