Commit 26982eea5d848e64a67756eb46c85a4899f78d34

Authored by 吴启风
1 parent 4d8b0da4

feat:环节页点击节流优化

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