diff --git a/lib/common/widgets/throttledGesture_gesture_detector.dart b/lib/common/widgets/throttledGesture_gesture_detector.dart new file mode 100644 index 0000000..5cf70fe --- /dev/null +++ b/lib/common/widgets/throttledGesture_gesture_detector.dart @@ -0,0 +1,42 @@ +import 'dart:async'; +import 'package:flutter/material.dart'; + +///带节流功能的GestureDetector +class ThrottledGestureDetector extends StatefulWidget { + final Widget child; + final VoidCallback onTap; + final int throttleTime; + + const ThrottledGestureDetector({ + super.key, + required this.child, + required this.onTap, + this.throttleTime = 500, // 默认节流时间为500毫秒 + }); + + @override + _ThrottledGestureDetectorState createState() => + _ThrottledGestureDetectorState(); +} + +class _ThrottledGestureDetectorState extends State { + bool _isThrottled = false; + + void _handleTap() { + if (!_isThrottled) { + widget.onTap(); + _isThrottled = true; + Timer(Duration(milliseconds: widget.throttleTime), () { + _isThrottled = false; + }); + } + } + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: _handleTap, + child: widget.child, + ); + } +} diff --git a/lib/pages/practice/bloc/topic_picture_bloc.dart b/lib/pages/practice/bloc/topic_picture_bloc.dart index d84f1ce..5c4e7ee 100644 --- a/lib/pages/practice/bloc/topic_picture_bloc.dart +++ b/lib/pages/practice/bloc/topic_picture_bloc.dart @@ -83,7 +83,7 @@ class TopicPictureBloc extends BaseSectionBloc(_initVoiceSdk); on(_selectItemLoad); on(_requestData); - on(_voiceXsTest); + on(_voiceXsStart); on(_voiceXsStop); on(_questionVoicePlay); on((event, emit) { @@ -231,7 +231,7 @@ class TopicPictureBloc extends BaseSectionBloc emitter) async { + void _voiceXsStart(XSVoiceStartEvent event,Emitter emitter) async { await audioPlayer.stop(); // 调用封装好的权限检查和请求方法 bool result = await permissionCheckAndRequest( diff --git a/lib/pages/practice/bloc/topic_picture_event.dart b/lib/pages/practice/bloc/topic_picture_event.dart index 4914c1b..c2e416c 100644 --- a/lib/pages/practice/bloc/topic_picture_event.dart +++ b/lib/pages/practice/bloc/topic_picture_event.dart @@ -14,11 +14,11 @@ class XSVoiceInitEvent extends TopicPictureEvent { } ///开始评测 -class XSVoiceTestEvent extends TopicPictureEvent { +class XSVoiceStartEvent extends TopicPictureEvent { final String testWord; final String type; final String userId; - XSVoiceTestEvent(this.testWord,this.type,this.userId); + XSVoiceStartEvent(this.testWord,this.type,this.userId); } ///终止评测 diff --git a/lib/pages/practice/topic_picture_page.dart b/lib/pages/practice/topic_picture_page.dart index 87ba70d..dd3cf43 100644 --- a/lib/pages/practice/topic_picture_page.dart +++ b/lib/pages/practice/topic_picture_page.dart @@ -10,6 +10,7 @@ import 'package:wow_english/pages/practice/topic_type.dart'; import 'package:wow_english/route/route.dart'; import 'package:wow_english/utils/toast_util.dart'; +import '../../common/widgets/throttledGesture_gesture_detector.dart'; import 'bloc/topic_picture_bloc.dart'; import 'widgets/practice_header_widget.dart'; @@ -479,20 +480,23 @@ class _TopicPicturePage extends StatelessWidget { ), ), 70.verticalSpace, - GestureDetector( + ThrottledGestureDetector( + throttleTime: 1000, onTap: () { if (bloc.voicePlayState == VoicePlayState.playing) { - showToast('正在播放音屏,不能终止'); + showToast('正在播放音频,不能终止'); return; } if (bloc.isVoicing) { + bloc.add(XSVoiceStopEvent()); return; } - if (topics?.type == 5 || topics?.type == 7) { - bloc.add(XSVoiceTestEvent(topics?.keyWord??'', '0',UserUtil.getUser()!.id.toString())); + if (topics?.type == TopicType.voiceQuestion.value || + topics?.type == TopicType.voiceWord.value) { + bloc.add(XSVoiceStartEvent(topics?.keyWord??'', '0',UserUtil.getUser()!.id.toString())); } else { - bloc.add(XSVoiceTestEvent(topics?.word??'', '0',UserUtil.getUser()!.id.toString())); + bloc.add(XSVoiceStartEvent(topics?.word??'', '0',UserUtil.getUser()!.id.toString())); } }, child: Image.asset( diff --git a/lib/pages/practice/topic_type.dart b/lib/pages/practice/topic_type.dart index 91ac9ac..bcda94c 100644 --- a/lib/pages/practice/topic_type.dart +++ b/lib/pages/practice/topic_type.dart @@ -13,7 +13,10 @@ enum TopicType { questionImageSelect, ///语音问答 - voiceQuestion + voiceQuestion, + + ///跟读单词(目前没实现,但是有一处判断,就先把类型定义出来) + voiceWord } extension TopicTypeExtension on TopicType { @@ -29,6 +32,8 @@ extension TopicTypeExtension on TopicType { return 4; case TopicType.voiceQuestion: return 5; + case TopicType.voiceWord: + return 7; default: throw ArgumentError('Unknown topic type'); } diff --git a/lib/pages/reading/bloc/reading_bloc.dart b/lib/pages/reading/bloc/reading_bloc.dart index 3012b82..9be43e7 100644 --- a/lib/pages/reading/bloc/reading_bloc.dart +++ b/lib/pages/reading/bloc/reading_bloc.dart @@ -179,7 +179,9 @@ class ReadingPageBloc void _pageControllerChange(CurrentPageIndexChangeEvent event, Emitter emitter) async { _currentPage = event.pageIndex; + debugPrint("WQF _playOriginalAudioInner begin"); _playOriginalAudioInner(null); + debugPrint("WQF _playOriginalAudioInner end"); emitter(CurrentPageIndexState()); } @@ -227,6 +229,7 @@ class ReadingPageBloc audioPlayer.stop(); } else { _isOriginAudioPlaying = true; + debugPrint("WQF _playOriginalAudioInner _isOriginAudioPlaying: true"); audioUrl ??= currentPageData()?.audioUrl ?? ''; _playAudio(audioUrl); } diff --git a/lib/pages/section/section_page.dart b/lib/pages/section/section_page.dart index cf6511e..5febdc4 100644 --- a/lib/pages/section/section_page.dart +++ b/lib/pages/section/section_page.dart @@ -158,15 +158,19 @@ class _SectionPageView extends StatelessWidget { bloc.add(CurrentUnitIndexChangeEvent(index)); }, itemBuilder: (context, index) { - return ScrollConfiguration( - ///去掉 Android 上默认的边缘拖拽效果 - behavior: ScrollConfiguration.of(context) - .copyWith(overscroll: false), - child: _itemTransCard( - bloc.getCourseUnitDetail(pageIndex: index), - index, - context), - ); + // return ScrollConfiguration( + // ///去掉 Android 上默认的边缘拖拽效果 + // behavior: ScrollConfiguration.of(context) + // .copyWith(overscroll: false), + // child: _itemTransCard( + // bloc.getCourseUnitDetail(pageIndex: index), + // index, + // context), + // ); + return _itemTransCard( + bloc.getCourseUnitDetail(pageIndex: index), + index, + context); }), ), // 设置外部padding, )),