Blame view

lib/pages/section/section_page.dart 10.9 KB
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
1
  import 'package:flutter/cupertino.dart';
95edef4f   liangchengyou   feat:更新适配代码
2
  import 'package:flutter/material.dart';
60e47f7c   liangchengyou   feat:课程选择功能
3
  import 'package:flutter_bloc/flutter_bloc.dart';
d35a4e87   liangchengyou   feat:磨耳朵功能UI
4
  import 'package:flutter_screenutil/flutter_screenutil.dart';
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
5
  import 'package:nested_scroll_views/material.dart';
f5fc01c1   liangchengyou   feat:修复首页进入个人信息页闪退问题
6
  import 'package:wow_english/common/core/user_util.dart';
d35a4e87   liangchengyou   feat:磨耳朵功能UI
7
  import 'package:wow_english/common/extension/string_extension.dart';
2187c85f   吴启风   feat:课程结构调整
8
  import 'package:wow_english/models/course_unit_entity.dart';
46675a89   吴启风   feat:过渡页-视频环节
9
  import 'package:wow_english/pages/section/section_type.dart';
e620143b   吴启风   feat:单元&课程解锁状态蒙层ui
10
  import 'package:wow_english/pages/section/widgets/section_item.dart';
2187c85f   吴启风   feat:课程结构调整
11
12
  import 'package:wow_english/pages/section/widgets/section_bouns_item.dart';
  import 'package:wow_english/pages/section/widgets/section_header_widget.dart';
60e47f7c   liangchengyou   feat:课程选择功能
13
  import 'package:wow_english/route/route.dart';
c61b3c1a   Key   feat: toast_util....
14
  import 'package:wow_english/utils/toast_util.dart';
95edef4f   liangchengyou   feat:更新适配代码
15
  
2187c85f   吴启风   feat:课程结构调整
16
17
  import '../../models/course_section_entity.dart';
  import 'bloc/section_bloc.dart';
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
18
  import 'courese_module_model.dart';
4b358e22   liangchengyou   feat:调整文件结构
19
  
2187c85f   吴启风   feat:课程结构调整
20
21
  /// 环节列表页
  class SectionPage extends StatelessWidget {
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
22
    const SectionPage(
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
23
        {super.key, required this.courseUnitEntity, required this.courseUnitId});
8988aa69   liangchengyou   feat:首页+课程列表数据获取
24
  
2187c85f   吴启风   feat:课程结构调整
25
26
27
    final CourseUnitEntity courseUnitEntity;
  
    /// unitId
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
28
    final int courseUnitId;
95edef4f   liangchengyou   feat:更新适配代码
29
30
31
  
    @override
    Widget build(BuildContext context) {
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
32
33
34
      int initialPage = courseUnitEntity.courseUnitVOList
              ?.indexWhere((element) => element.id == courseUnitId) ??
          0;
60e47f7c   liangchengyou   feat:课程选择功能
35
      return BlocProvider(
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
36
37
        create: (context) => SectionBloc(courseUnitEntity, initialPage,
            PageController(initialPage: initialPage), ScrollController()),
2187c85f   吴启风   feat:课程结构调整
38
        child: _SectionPageView(context),
60e47f7c   liangchengyou   feat:课程选择功能
39
40
41
42
      );
    }
  }
  
2187c85f   吴启风   feat:课程结构调整
43
44
  class _SectionPageView extends StatelessWidget {
    const _SectionPageView(this.context);
454dc387   吴启风   feat:原阶段选择页(首页)增加...
45
46
47
  
    final BuildContext context;
  
60e47f7c   liangchengyou   feat:课程选择功能
48
49
    @override
    Widget build(BuildContext context) {
2187c85f   吴启风   feat:课程结构调整
50
51
      final bloc = BlocProvider.of<SectionBloc>(context);
      return BlocListener<SectionBloc, SectionState>(
3c1d5c64   liangchengyou   feat:练习功能完成
52
53
        listener: (context, state) {
          if (state is RequestVideoLessonState) {
2187c85f   吴启风   feat:课程结构调整
54
            final videoUrl = bloc.processEntity?.videos?.videoUrl ?? '';
3c1d5c64   liangchengyou   feat:练习功能完成
55
            var title = '';
46675a89   吴启风   feat:过渡页-视频环节
56
            if (state.type == SectionType.song.value) {
3c1d5c64   liangchengyou   feat:练习功能完成
57
58
59
              title = 'song';
            }
  
46675a89   吴启风   feat:过渡页-视频环节
60
            if (state.type == SectionType.video.value) {
3c1d5c64   liangchengyou   feat:练习功能完成
61
62
63
              title = 'video';
            }
  
46675a89   吴启风   feat:过渡页-视频环节
64
            if (state.type == SectionType.bouns.value) {
3c1d5c64   liangchengyou   feat:练习功能完成
65
66
              title = 'bonus';
            }
997ea0d6   liangchengyou   feat:绘本闪退问题修复
67
  
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
68
69
70
            if (videoUrl.isEmpty || !videoUrl.contains('http')) {
              return;
            }
2187c85f   吴启风   feat:课程结构调整
71
72
73
            pushNamed(AppRouteName.lookVideo, arguments: {
              'videoUrl': videoUrl,
              'title': title,
46675a89   吴启风   feat:过渡页-视频环节
74
75
              'courseLessonId': state.courseLessonId,
              'isTopic': true
2187c85f   吴启风   feat:课程结构调整
76
            }).then((value) {
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
77
              if (value != null) {
46675a89   吴启风   feat:过渡页-视频环节
78
                Map<String, dynamic> dataMap = value as Map<String, dynamic>;
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
79
80
81
82
                bloc.add(RequestEndClassEvent(
                    dataMap['courseLessonId']!, dataMap['isCompleted'],
                    currentTime: dataMap['currentTime'],
                    autoNextSection: dataMap['nextSection']));
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
83
84
85
86
87
88
              }
            });
            return;
          }
  
          if (state is RequestEnterClassState) {
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
89
90
            if (state.courseType != SectionType.practice.value &&
                state.courseType != SectionType.pictureBook.value) {
2187c85f   吴启风   feat:课程结构调整
91
              ///视频类型
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
92
              ///获取视频课程内容
2187c85f   吴启风   feat:课程结构调整
93
94
              bloc.add(RequestVideoLessonEvent(
                  state.courseLessonId, state.courseType));
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
95
96
97
              return;
            }
  
46675a89   吴启风   feat:过渡页-视频环节
98
            if (state.courseType == SectionType.pictureBook.value) {
2187c85f   吴启风   feat:课程结构调整
99
100
101
102
              //绘本
              pushNamed(AppRouteName.reading,
                      arguments: {'courseLessonId': state.courseLessonId})
                  .then((value) {
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
103
                if (value != null) {
22f36232   吴启风   feat:过渡页-练习环节
104
105
                  Map<String, dynamic> dataMap = value as Map<String, dynamic>;
                  bloc.add(RequestEndClassEvent(
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
106
107
108
109
110
                    dataMap['courseLessonId']!,
                    dataMap['isCompleted'],
                    currentStep: dataMap['currentStep'],
                    autoNextSection: dataMap['nextSection'],
                  ));
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
111
112
113
114
115
                }
              });
              return;
            }
  
46675a89   吴启风   feat:过渡页-视频环节
116
            if (state.courseType == SectionType.practice.value) {
2187c85f   吴启风   feat:课程结构调整
117
118
119
120
              //练习
              pushNamed(AppRouteName.topicPic,
                      arguments: {'courseLessonId': state.courseLessonId})
                  .then((value) {
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
121
                if (value != null) {
22f36232   吴启风   feat:过渡页-练习环节
122
123
                  Map<String, dynamic> dataMap = value as Map<String, dynamic>;
                  bloc.add(RequestEndClassEvent(
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
124
125
126
                      dataMap['courseLessonId']!, dataMap['isCompleted'],
                      currentStep: dataMap['currentStep'],
                      autoNextSection: dataMap['nextSection']));
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
127
128
                }
              });
3c1d5c64   liangchengyou   feat:练习功能完成
129
130
              return;
            }
3c1d5c64   liangchengyou   feat:练习功能完成
131
132
          }
        },
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
133
        child: _sectionView(),
95edef4f   liangchengyou   feat:更新适配代码
134
135
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
136
  
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
137
    Widget _sectionView() =>
2187c85f   吴启风   feat:课程结构调整
138
139
        BlocBuilder<SectionBloc, SectionState>(builder: (context, state) {
          final bloc = BlocProvider.of<SectionBloc>(context);
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
140
141
142
143
144
145
146
          return Scaffold(
            body: Container(
              color: Colors.white,
              child: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
2187c85f   吴启风   feat:课程结构调整
147
                    SectionHeaderWidget(
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
148
                        title: bloc.getCourseUnitDetail().name,
2187c85f   吴启风   feat:课程结构调整
149
                        courseModuleCode: bloc.courseUnitEntity.courseModuleCode),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
150
                    Expanded(
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
151
152
153
154
155
156
157
158
159
160
161
162
163
164
                        child: Padding(
                      padding: EdgeInsets.symmetric(horizontal: 10.w),
                      child: OverflowBox(
                        child: NestedPageView.builder(
                            itemCount: bloc.unlockPageCount(),
                            controller: bloc.pageController,
                            onPageChanged: (int index) {
                              bloc.add(CurrentUnitIndexChangeEvent(index));
                            },
                            itemBuilder: (context, index) {
                              return ScrollConfiguration(
                                ///去掉 Android 上默认的边缘拖拽效果
                                behavior: ScrollConfiguration.of(context)
                                    .copyWith(overscroll: false),
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
165
166
167
168
                                child: _itemTransCard(
                                    bloc.getCourseUnitDetail(pageIndex: index),
                                    index,
                                    context),
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
                              );
                            }),
                      ), // 设置外部padding,
                    )),
                    SafeArea(
                      child: Padding(
                        padding: EdgeInsets.symmetric(horizontal: 13.w),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            SizedBox(
                              height: 47.h,
                              width: 80.w,
                            ),
                            Container(
                              decoration: BoxDecoration(
                                color: CourseModuleModel(
                                        bloc.courseUnitEntity.courseModuleCode ??
                                            'Phase-1')
                                    .color,
                                borderRadius: BorderRadius.circular(14.5.r),
                              ),
                              padding: EdgeInsets.symmetric(
                                  vertical: 8.h, horizontal: 24.w),
                              child: Text(
                                '${bloc.currentPage + 1}/${bloc.unlockPageCount()}',
                                style: TextStyle(
                                    color: Colors.white, fontSize: 12.sp),
                              ),
                            ),
                            Image.asset(
                              CourseModuleModel(
                                      bloc.courseUnitEntity.courseModuleCode ??
                                          'Phase-1')
                                  .courseModuleLogo
                                  .assetPng,
                              height: 47.h,
                              width: 80.w,
                              // color: Colors.red,
                            ),
                          ],
                        ),
                      ),
                    )
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
213
214
215
                  ],
                ),
              ),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
216
            ),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
217
218
          );
        });
056970d8   Key   feat: api
219
  }
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
220
  
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
221
222
  Widget _itemTransCard(
      CourseUnitDetail courseUnitDetail, int pageIndex, BuildContext context) {
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
223
    final bloc = BlocProvider.of<SectionBloc>(context);
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
    List<CourseSectionEntity>? courseSectionEntities =
        bloc.courseSectionDatasMap[courseUnitDetail.id];
    if (courseSectionEntities == null) {
      bloc.add(RequestDataEvent(courseUnitDetail.id!));
      return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              '暂无数据',
              style: TextStyle(fontSize: 24.0),
            ),
            const SizedBox(height: 16.0),
            // 间距
            CircularProgressIndicator(
                color: CourseModuleModel(
                        bloc.courseUnitEntity.courseModuleCode ?? 'Phase-1')
                    .color),
            // 加载动画
          ],
        ),
      );
    } else {
      return NestedListView.builder(
          itemCount: bloc.courseSectionDatasMap[courseUnitDetail.id]?.length ?? 0,
          scrollDirection: Axis.horizontal,
          itemBuilder: (BuildContext context, int index) {
            CourseSectionEntity sectionData = courseSectionEntities[index];
            if (sectionData.courseType == SectionType.bouns.value) {
              //彩蛋
              return GestureDetector(
                onTap: () {
                  if (!UserUtil.isLogined()) {
                    pushNamed(AppRouteName.login);
                    return;
                  }
                  if (sectionData.lock == true) {
                    showToast('当前课程暂未解锁');
                    return;
                  }
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
264
  
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
                  ///进入课堂
                  bloc.add(RequestEnterClassEvent(
                      sectionData.id.toString(), sectionData.courseType));
                },
                child: SectionBoundsItem(
                  imageUrl: sectionData.coverUrl,
                ),
              );
            } else {
              return GestureDetector(
                onTap: () {
                  if (!UserUtil.isLogined()) {
                    pushNamed(AppRouteName.login);
                    return;
                  }
                  if (sectionData.lock == true) {
                    showToast('当前课程暂未解锁');
                    return;
                  }
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
284
  
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
285
286
287
288
                  ///进入课堂
                  bloc.add(RequestEnterClassEvent(
                      sectionData.id.toString(), sectionData.courseType));
                },
e620143b   吴启风   feat:单元&课程解锁状态蒙层ui
289
290
                child: SectionItem(
                  courseModuleId: bloc.courseUnitEntity.courseModuleCode,
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
291
292
293
294
295
296
                  lessons: sectionData,
                ),
              );
            }
          });
    }
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
297
  }