Commit 0cbdbb3480bd41cd223ef9fbc64649dcb0f718c1

Authored by 吴启风
1 parent 009cf00d

feat:环节列表页返回单元列表页是增加刷新逻辑

lib/pages/section/bloc/section_bloc.dart
... ... @@ -40,6 +40,9 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> {
40 40  
41 41 CourseUnitEntity get courseUnitEntity => _courseUnitEntity;
42 42  
  43 + ///单元列表是否有刷新,有的话返回上一页时通知其刷新接口数据
  44 + bool courseUnitEntityChanged = false;
  45 +
43 46 ///courseUnitId与课程环节列表的映射
44 47 final Map<int, List<CourseSectionEntity>?> _courseSectionDatasMap = {};
45 48  
... ... @@ -154,10 +157,11 @@ class SectionBloc extends Bloc&lt;SectionEvent, SectionState&gt; {
154 157  
155 158 ///未锁定的页(单元)数
156 159 int unlockPageCount() {
157   - return _courseUnitEntity.courseUnitVOList
158   - ?.indexWhereOrNull((element) => element.lock == true) ??
159   - _courseUnitEntity.courseUnitVOList?.length ??
160   - 0;
  160 + // return _courseUnitEntity.courseUnitVOList
  161 + // ?.indexWhereOrNull((element) => element.lock == true) ??
  162 + // _courseUnitEntity.courseUnitVOList?.length ??
  163 + // 0;
  164 + return _courseUnitEntity.courseUnitVOList?.length ?? 0;
161 165 }
162 166  
163 167 ///当前页的课程详情
... ... @@ -278,6 +282,7 @@ class SectionBloc extends Bloc&lt;SectionEvent, SectionState&gt; {
278 282 if (nextCourseUnitDetail?.lock == false) {
279 283 ///解锁状态从锁定到解锁,覆盖原unit数据并刷新ui
280 284 _courseUnitEntity = newCourseUnitEntity!;
  285 + courseUnitEntityChanged = true;
281 286 emitter(LessonDataLoadState());
282 287  
283 288 return checkCourseSectionLockedOfNextUnit(courseLessonId, nextCourseUnitDetail!.id!, emitter);
... ...
lib/pages/section/section_page.dart
... ... @@ -38,9 +38,9 @@ class SectionPage extends StatelessWidget {
38 38 initialPage,
39 39 PageController(initialPage: initialPage),
40 40 ScrollController(),
41   - ScrollController())
  41 + ScrollController()),
42 42 //为了触发指示器进入后计算位置
43   - ..add(CurrentUnitIndexChangeEvent(initialPage)),
  43 + // ..add(CurrentUnitIndexChangeEvent(initialPage)),
44 44 child: _SectionPageView(context),
45 45 );
46 46 }
... ... @@ -152,7 +152,12 @@ class _SectionPageView extends StatelessWidget {
152 152 children: [
153 153 SectionHeaderWidget(
154 154 title: bloc.getCourseUnitDetail().name,
155   - courseModuleCode: bloc.courseUnitEntity.courseModuleCode),
  155 + courseModuleCode: bloc.courseUnitEntity.courseModuleCode,
  156 + onBack: () {
  157 + popPage(data: {
  158 + 'needRefresh': bloc.courseUnitEntityChanged,
  159 + });
  160 + }),
156 161 Expanded(
157 162 child: Padding(
158 163 padding: EdgeInsets.symmetric(horizontal: 10.w),
... ...
lib/pages/section/widgets/section_header_widget.dart
... ... @@ -7,12 +7,14 @@ import &#39;package:wow_english/pages/user/bloc/user_bloc.dart&#39;;
7 7 import '../courese_module_model.dart';
8 8  
9 9 class SectionHeaderWidget extends StatelessWidget {
10   - const SectionHeaderWidget({super.key, this.title, this.courseModuleCode});
  10 + const SectionHeaderWidget({super.key, this.title, this.courseModuleCode, this.onBack});
11 11  
12 12 final String? title;
13 13  
14 14 final String? courseModuleCode;
15 15  
  16 + final VoidCallback? onBack;
  17 +
16 18 @override
17 19 Widget build(BuildContext context) {
18 20 return BlocBuilder<UserBloc, UserState>(
... ... @@ -27,7 +29,11 @@ class SectionHeaderWidget extends StatelessWidget {
27 29 ScreenUtil().bottomBarHeight.horizontalSpace,
28 30 GestureDetector(
29 31 onTap: () {
30   - Navigator.pop(context);
  32 + if (onBack == null) {
  33 + Navigator.pop(context);
  34 + } else {
  35 + onBack!();
  36 + }
31 37 },
32 38 child: Container(
33 39 alignment: Alignment.center,
... ...
lib/pages/unit/view.dart
... ... @@ -65,7 +65,15 @@ class UnitPage extends StatelessWidget {
65 65 arguments: {
66 66 'courseUnitEntity': bloc.unitData,
67 67 'courseUnitId': data.id
68   - });
  68 + }).then((value) {
  69 + if (value != null) {
  70 + Map<String, dynamic> dataMap = value as Map<String, dynamic>;
  71 + bool needRefresh = dataMap['needRefresh'];
  72 + if (needRefresh) {
  73 + bloc.add(RequestUnitDataEvent(courseModuleEntity?.id));
  74 + }
  75 + }
  76 + });
69 77 },
70 78 child: CourseUnitItem(
71 79 unitEntity: bloc.unitData!,
... ...