Commit 820997e60600aa3f953e49bab5b06ea4c6ebf9ad

Authored by 吴启风
1 parent 66a7e3e7

feat:过渡页-绘本环节

lib/pages/reading/bloc/reading_bloc.dart
@@ -6,11 +6,15 @@ import 'package:flutter_bloc/flutter_bloc.dart'; @@ -6,11 +6,15 @@ import 'package:flutter_bloc/flutter_bloc.dart';
6 import 'package:flutter_easyloading/flutter_easyloading.dart'; 6 import 'package:flutter_easyloading/flutter_easyloading.dart';
7 import 'package:permission_handler/permission_handler.dart'; 7 import 'package:permission_handler/permission_handler.dart';
8 import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart'; 8 import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart';
  9 +import 'package:wow_english/pages/section/subsection/base_section/bloc.dart';
  10 +import 'package:wow_english/pages/section/subsection/base_section/event.dart';
  11 +import 'package:wow_english/pages/section/subsection/base_section/state.dart';
9 12
10 import '../../../common/core/user_util.dart'; 13 import '../../../common/core/user_util.dart';
11 import '../../../common/request/dao/listen_dao.dart'; 14 import '../../../common/request/dao/listen_dao.dart';
12 import '../../../common/request/exception.dart'; 15 import '../../../common/request/exception.dart';
13 import '../../../models/course_process_entity.dart'; 16 import '../../../models/course_process_entity.dart';
  17 +import '../../../route/route.dart';
14 import '../../../utils/loading.dart'; 18 import '../../../utils/loading.dart';
15 19
16 import '../../../utils/log_util.dart'; 20 import '../../../utils/log_util.dart';
@@ -33,7 +37,8 @@ enum VoicePlayState { @@ -33,7 +37,8 @@ enum VoicePlayState {
33 stop 37 stop
34 } 38 }
35 39
36 -class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { 40 +class ReadingPageBloc
  41 + extends BaseSectionBloc<ReadingPageEvent, ReadingPageState> {
37 final PageController pageController; 42 final PageController pageController;
38 43
39 final String courseLessonId; 44 final String courseLessonId;
@@ -211,7 +216,7 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; { @@ -211,7 +216,7 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
211 } 216 }
212 217
213 ///播放原音音频 218 ///播放原音音频
214 - Future<void> _playOriginalAudioInner(String? audioUrl) async { 219 + void _playOriginalAudioInner(String? audioUrl) async {
215 if (_isRecordAudioPlaying) { 220 if (_isRecordAudioPlaying) {
216 _isRecordAudioPlaying = false; 221 _isRecordAudioPlaying = false;
217 } 222 }
@@ -219,7 +224,7 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; { @@ -219,7 +224,7 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
219 "_playOriginalAudio _isRecordAudioPlaying=$_isRecordAudioPlaying _isOriginAudioPlaying=$_isOriginAudioPlaying url=$audioUrl"); 224 "_playOriginalAudio _isRecordAudioPlaying=$_isRecordAudioPlaying _isOriginAudioPlaying=$_isOriginAudioPlaying url=$audioUrl");
220 if (_isOriginAudioPlaying) { 225 if (_isOriginAudioPlaying) {
221 _isOriginAudioPlaying = false; 226 _isOriginAudioPlaying = false;
222 - await audioPlayer.stop(); 227 + audioPlayer.stop();
223 } else { 228 } else {
224 _isOriginAudioPlaying = true; 229 _isOriginAudioPlaying = true;
225 audioUrl ??= currentPageData()?.audioUrl ?? ''; 230 audioUrl ??= currentPageData()?.audioUrl ?? '';
@@ -265,8 +270,17 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; { @@ -265,8 +270,17 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
265 } 270 }
266 271
267 void nextPage() { 272 void nextPage() {
268 - if (_currentPage >= dataCount() - 1) {  
269 - ///todo 最后一页了 273 + if (currentPage >= dataCount()) {
  274 + sectionComplete(() {
  275 + popPage(data: {
  276 + 'currentStep': currentPage,
  277 + 'courseLessonId': courseLessonId,
  278 + 'isCompleted': true,
  279 + 'nextSection': true
  280 + });
  281 + }, againSectionTap: () {
  282 + pageController.jumpToPage(0);
  283 + });
270 } else { 284 } else {
271 _currentPage += 1; 285 _currentPage += 1;
272 pageController.nextPage( 286 pageController.nextPage(
@@ -291,14 +305,14 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; { @@ -291,14 +305,14 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
291 305
292 void startRecord(String content) async { 306 void startRecord(String content) async {
293 // 调用封装好的权限检查和请求方法 307 // 调用封装好的权限检查和请求方法
294 - bool result = await permissionCheckAndRequest(  
295 - context,  
296 - Permission.microphone,  
297 - "录音"  
298 - ); 308 + bool result =
  309 + await permissionCheckAndRequest(context, Permission.microphone, "录音");
299 if (result) { 310 if (result) {
300 - methodChannel.invokeMethod(  
301 - 'startVoice', {'word': content, 'type': '0', 'userId': UserUtil.getUser()?.id.toString()}); 311 + methodChannel.invokeMethod('startVoice', {
  312 + 'word': content,
  313 + 'type': '0',
  314 + 'userId': UserUtil.getUser()?.id.toString()
  315 + });
302 } 316 }
303 } 317 }
304 318
@@ -313,7 +327,20 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; { @@ -313,7 +327,20 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
313 currentPageData()?.recordScore = overall; 327 currentPageData()?.recordScore = overall;
314 currentPageData()?.recordUrl = args['audioUrl'] + '.mp3'; 328 currentPageData()?.recordUrl = args['audioUrl'] + '.mp3';
315 ///完成录音后紧接着播放录音 329 ///完成录音后紧接着播放录音
316 - _playRecordAudioInner(); 330 + await _playRecordAudioInner();
  331 + if (isLastPage()) {
  332 + sectionComplete(() {
  333 + popPage(data: {
  334 + 'currentStep': currentPage,
  335 + 'courseLessonId': courseLessonId,
  336 + 'isCompleted': true,
  337 + 'nextSection': true
  338 + });
  339 + }, againSectionTap: () {
  340 + _resetLocalResult();
  341 + pageController.jumpToPage(0);
  342 + });
  343 + }
317 // emitter(FeedbackState()); 344 // emitter(FeedbackState());
318 } 345 }
319 346
@@ -338,8 +365,11 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; { @@ -338,8 +365,11 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
338 nextPage(); 365 nextPage();
339 } 366 }
340 367
341 - Log.d("_onAudioPlayComplete _isOriginAudioPlaying=$_isOriginAudioPlaying _voicePlayState=$_voicePlayState recordUrl=${currentPageData()?.recordUrl?.isNotEmpty}");  
342 - if (_isOriginAudioPlaying && _voicePlayState == VoicePlayState.completed && currentPageData()?.recordUrl?.isNotEmpty != true) { 368 + Log.d(
  369 + "_onAudioPlayComplete _isOriginAudioPlaying=$_isOriginAudioPlaying _voicePlayState=$_voicePlayState recordUrl=${currentPageData()?.recordUrl?.isNotEmpty}");
  370 + if (_isOriginAudioPlaying &&
  371 + _voicePlayState == VoicePlayState.completed &&
  372 + currentPageData()?.recordUrl?.isNotEmpty != true) {
343 ///如果刚刚完成原音播放&&录音为空,则开始录音 373 ///如果刚刚完成原音播放&&录音为空,则开始录音
344 startRecord(currentPageData()?.word ?? ''); 374 startRecord(currentPageData()?.word ?? '');
345 } 375 }
@@ -354,11 +384,21 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; { @@ -354,11 +384,21 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
354 _isRecordAudioPlaying = false; 384 _isRecordAudioPlaying = false;
355 } 385 }
356 386
357 - void _onVoiceXsStateChange(  
358 - OnXSVoiceStateChangeEvent event,  
359 - Emitter<ReadingPageState> emitter  
360 - ) async { 387 + void _onVoiceXsStateChange(OnXSVoiceStateChangeEvent event,
  388 + Emitter<ReadingPageState> emitter) async {
361 emitter(XSVoiceTestState()); 389 emitter(XSVoiceTestState());
362 } 390 }
363 -}  
364 391
  392 + ///是否是最后一页
  393 + bool isLastPage() {
  394 + return currentPage == dataCount();
  395 + }
  396 +
  397 + ///重置数据
  398 + void _resetLocalResult() {
  399 + _entity?.readings?.forEach((element) {
  400 + element.recordScore = null;
  401 + element.recordUrl = null;
  402 + });
  403 + }
  404 +}
lib/pages/reading/bloc/reading_event.dart
1 part of 'reading_bloc.dart'; 1 part of 'reading_bloc.dart';
2 2
3 @immutable 3 @immutable
4 -abstract class ReadingPageEvent {} 4 +abstract class ReadingPageEvent extends BaseSectionEvent {}
5 5
6 ///页面初始化 6 ///页面初始化
7 class InitBlocEvent extends ReadingPageEvent {} 7 class InitBlocEvent extends ReadingPageEvent {}
lib/pages/reading/bloc/reading_state.dart
1 part of 'reading_bloc.dart'; 1 part of 'reading_bloc.dart';
2 2
3 @immutable 3 @immutable
4 -abstract class ReadingPageState {} 4 +abstract class ReadingPageState extends BaseSectionState {}
5 5
6 class ReadingPageInitial extends ReadingPageState {} 6 class ReadingPageInitial extends ReadingPageState {}
7 7
lib/pages/reading/reading_page.dart
@@ -88,8 +88,9 @@ class _ReadingPage extends StatelessWidget { @@ -88,8 +88,9 @@ class _ReadingPage extends StatelessWidget {
88 onPressed: () { 88 onPressed: () {
89 popPage( 89 popPage(
90 data:{ 90 data:{
91 - 'currentStep':bloc.currentPage.toString(),  
92 - 'courseLessonId':bloc.courseLessonId 91 + 'currentStep':bloc.currentPage,
  92 + 'courseLessonId':bloc.courseLessonId,
  93 + 'isCompleted':bloc.isLastPage(),
93 } 94 }
94 ); 95 );
95 }, 96 },
lib/pages/section/bloc/section_bloc.dart
@@ -111,6 +111,7 @@ class SectionBloc extends Bloc&lt;SectionEvent, SectionState&gt; { @@ -111,6 +111,7 @@ class SectionBloc extends Bloc&lt;SectionEvent, SectionState&gt; {
111 if (event.autoNextSection) { 111 if (event.autoNextSection) {
112 final nextCourseSection = 112 final nextCourseSection =
113 getNextCourseSection(int.parse(event.courseLessonId)); 113 getNextCourseSection(int.parse(event.courseLessonId));
  114 + debugPrint("WQF nextCourseSection: $nextCourseSection");
114 ///进入课堂 115 ///进入课堂
115 add(RequestEnterClassEvent(nextCourseSection!.id.toString(), 116 add(RequestEnterClassEvent(nextCourseSection!.id.toString(),
116 nextCourseSection.courseType)); 117 nextCourseSection.courseType));