Commit 820997e60600aa3f953e49bab5b06ea4c6ebf9ad
1 parent
66a7e3e7
feat:过渡页-绘本环节
Showing
5 changed files
with
66 additions
and
24 deletions
lib/pages/reading/bloc/reading_bloc.dart
... | ... | @@ -6,11 +6,15 @@ import 'package:flutter_bloc/flutter_bloc.dart'; |
6 | 6 | import 'package:flutter_easyloading/flutter_easyloading.dart'; |
7 | 7 | import 'package:permission_handler/permission_handler.dart'; |
8 | 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 | 13 | import '../../../common/core/user_util.dart'; |
11 | 14 | import '../../../common/request/dao/listen_dao.dart'; |
12 | 15 | import '../../../common/request/exception.dart'; |
13 | 16 | import '../../../models/course_process_entity.dart'; |
17 | +import '../../../route/route.dart'; | |
14 | 18 | import '../../../utils/loading.dart'; |
15 | 19 | |
16 | 20 | import '../../../utils/log_util.dart'; |
... | ... | @@ -33,7 +37,8 @@ enum VoicePlayState { |
33 | 37 | stop |
34 | 38 | } |
35 | 39 | |
36 | -class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { | |
40 | +class ReadingPageBloc | |
41 | + extends BaseSectionBloc<ReadingPageEvent, ReadingPageState> { | |
37 | 42 | final PageController pageController; |
38 | 43 | |
39 | 44 | final String courseLessonId; |
... | ... | @@ -211,7 +216,7 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { |
211 | 216 | } |
212 | 217 | |
213 | 218 | ///播放原音音频 |
214 | - Future<void> _playOriginalAudioInner(String? audioUrl) async { | |
219 | + void _playOriginalAudioInner(String? audioUrl) async { | |
215 | 220 | if (_isRecordAudioPlaying) { |
216 | 221 | _isRecordAudioPlaying = false; |
217 | 222 | } |
... | ... | @@ -219,7 +224,7 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { |
219 | 224 | "_playOriginalAudio _isRecordAudioPlaying=$_isRecordAudioPlaying _isOriginAudioPlaying=$_isOriginAudioPlaying url=$audioUrl"); |
220 | 225 | if (_isOriginAudioPlaying) { |
221 | 226 | _isOriginAudioPlaying = false; |
222 | - await audioPlayer.stop(); | |
227 | + audioPlayer.stop(); | |
223 | 228 | } else { |
224 | 229 | _isOriginAudioPlaying = true; |
225 | 230 | audioUrl ??= currentPageData()?.audioUrl ?? ''; |
... | ... | @@ -265,8 +270,17 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { |
265 | 270 | } |
266 | 271 | |
267 | 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 | 284 | } else { |
271 | 285 | _currentPage += 1; |
272 | 286 | pageController.nextPage( |
... | ... | @@ -291,14 +305,14 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { |
291 | 305 | |
292 | 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 | 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<ReadingPageEvent, ReadingPageState> { |
313 | 327 | currentPageData()?.recordScore = overall; |
314 | 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 | 344 | // emitter(FeedbackState()); |
318 | 345 | } |
319 | 346 | |
... | ... | @@ -338,8 +365,11 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { |
338 | 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 | 374 | startRecord(currentPageData()?.word ?? ''); |
345 | 375 | } |
... | ... | @@ -354,11 +384,21 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { |
354 | 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 | 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
lib/pages/reading/bloc/reading_state.dart
lib/pages/reading/reading_page.dart
... | ... | @@ -88,8 +88,9 @@ class _ReadingPage extends StatelessWidget { |
88 | 88 | onPressed: () { |
89 | 89 | popPage( |
90 | 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<SectionEvent, SectionState> { |
111 | 111 | if (event.autoNextSection) { |
112 | 112 | final nextCourseSection = |
113 | 113 | getNextCourseSection(int.parse(event.courseLessonId)); |
114 | + debugPrint("WQF nextCourseSection: $nextCourseSection"); | |
114 | 115 | ///进入课堂 |
115 | 116 | add(RequestEnterClassEvent(nextCourseSection!.id.toString(), |
116 | 117 | nextCourseSection.courseType)); | ... | ... |