Commit 26982eea5d848e64a67756eb46c85a4899f78d34
1 parent
4d8b0da4
feat:环节页点击节流优化
Showing
2 changed files
with
14 additions
and
2 deletions
lib/pages/section/bloc/section_bloc.dart
| @@ -16,6 +16,7 @@ import 'package:wow_english/utils/toast_util.dart'; | @@ -16,6 +16,7 @@ import 'package:wow_english/utils/toast_util.dart'; | ||
| 16 | import '../../../models/course_section_entity.dart'; | 16 | import '../../../models/course_section_entity.dart'; |
| 17 | import '../../../models/course_unit_entity.dart'; | 17 | import '../../../models/course_unit_entity.dart'; |
| 18 | import '../../../utils/list_ext.dart'; | 18 | import '../../../utils/list_ext.dart'; |
| 19 | +import '../../../utils/log_util.dart'; | ||
| 19 | 20 | ||
| 20 | part 'section_event.dart'; | 21 | part 'section_event.dart'; |
| 21 | 22 | ||
| @@ -56,6 +57,9 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | @@ -56,6 +57,9 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | ||
| 56 | 57 | ||
| 57 | CourseProcessEntity? get processEntity => _processEntity; | 58 | CourseProcessEntity? get processEntity => _processEntity; |
| 58 | 59 | ||
| 60 | + ///点击环节后先请求数据再进入,标志位避免频繁点击多次请求(以及多次进入) | ||
| 61 | + bool _isRequesting = false; | ||
| 62 | + | ||
| 59 | SectionBloc(this._courseUnitEntity, this._currentPage, this._pageController, | 63 | SectionBloc(this._courseUnitEntity, this._currentPage, this._pageController, |
| 60 | this._listController, this._indicatorSrollController) | 64 | this._listController, this._indicatorSrollController) |
| 61 | : super(LessonInitial()) { | 65 | : super(LessonInitial()) { |
| @@ -100,12 +104,19 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | @@ -100,12 +104,19 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | ||
| 100 | if (e is ApiException) { | 104 | if (e is ApiException) { |
| 101 | showToast(e.message ?? '请求失败,请检查网络连接'); | 105 | showToast(e.message ?? '请求失败,请检查网络连接'); |
| 102 | } | 106 | } |
| 107 | + } finally { | ||
| 108 | + _isRequesting = false; | ||
| 103 | } | 109 | } |
| 104 | } | 110 | } |
| 105 | 111 | ||
| 106 | void _requestEnterClass( | 112 | void _requestEnterClass( |
| 107 | RequestEnterClassEvent event, Emitter<SectionState> emitter) async { | 113 | RequestEnterClassEvent event, Emitter<SectionState> emitter) async { |
| 108 | try { | 114 | try { |
| 115 | + Log.d("WQF _requestVideoLesson _isRequesting=$_isRequesting"); | ||
| 116 | + if (_isRequesting) { | ||
| 117 | + return; | ||
| 118 | + } | ||
| 119 | + _isRequesting = true; | ||
| 109 | await loading(() async { | 120 | await loading(() async { |
| 110 | await ListenDao.enterClass(event.courseLessonId); | 121 | await ListenDao.enterClass(event.courseLessonId); |
| 111 | emitter(RequestEnterClassState(event.courseLessonId, event.courseType)); | 122 | emitter(RequestEnterClassState(event.courseLessonId, event.courseType)); |
| @@ -113,6 +124,7 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | @@ -113,6 +124,7 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { | ||
| 113 | } catch (e) { | 124 | } catch (e) { |
| 114 | if (e is ApiException) { | 125 | if (e is ApiException) { |
| 115 | showToast(e.message ?? '请求失败,请检查网络连接'); | 126 | showToast(e.message ?? '请求失败,请检查网络连接'); |
| 127 | + _isRequesting = false; | ||
| 116 | } | 128 | } |
| 117 | } | 129 | } |
| 118 | } | 130 | } |
lib/pages/section/section_page.dart
| @@ -103,10 +103,10 @@ class _SectionPageView extends StatelessWidget { | @@ -103,10 +103,10 @@ class _SectionPageView extends StatelessWidget { | ||
| 103 | ///视频类型 | 103 | ///视频类型 |
| 104 | ///获取视频课程内容 | 104 | ///获取视频课程内容 |
| 105 | if (state.courseType == 1) { | 105 | if (state.courseType == 1) { |
| 106 | - await AudioPlayerUtil.getInstance() | 106 | + AudioPlayerUtil.getInstance() |
| 107 | .playAudio(AudioPlayerUtilType.musicTime); | 107 | .playAudio(AudioPlayerUtilType.musicTime); |
| 108 | } else { | 108 | } else { |
| 109 | - await AudioPlayerUtil.getInstance() | 109 | + AudioPlayerUtil.getInstance() |
| 110 | .playAudio(AudioPlayerUtilType.videoTime); | 110 | .playAudio(AudioPlayerUtilType.videoTime); |
| 111 | } | 111 | } |
| 112 | bloc.add(RequestVideoLessonEvent( | 112 | bloc.add(RequestVideoLessonEvent( |