Blame view

lib/pages/section/section_page.dart 14 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';
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
6
  import 'package:wow_english/common/core/module_cache.dart';
f5fc01c1   liangchengyou   feat:修复首页进入个人信息页闪退问题
7
  import 'package:wow_english/common/core/user_util.dart';
0493c104   吴启风   feat:带音乐点击防抖函数优化
8
  import 'package:wow_english/common/utils/click_with_music_controller.dart';
2187c85f   吴启风   feat:课程结构调整
9
  import 'package:wow_english/models/course_unit_entity.dart';
46675a89   吴启风   feat:过渡页-视频环节
10
  import 'package:wow_english/pages/section/section_type.dart';
e620143b   吴启风   feat:单元&课程解锁状态蒙层ui
11
  import 'package:wow_english/pages/section/widgets/section_item.dart';
2187c85f   吴启风   feat:课程结构调整
12
13
  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:课程选择功能
14
  import 'package:wow_english/route/route.dart';
025d8543   biao   首页gametime播放修改
15
  import 'package:wow_english/utils/audio_player_util.dart';
c61b3c1a   Key   feat: toast_util....
16
  import 'package:wow_english/utils/toast_util.dart';
95edef4f   liangchengyou   feat:更新适配代码
17
  
2187c85f   吴启风   feat:课程结构调整
18
  import '../../models/course_section_entity.dart';
2187c85f   吴启风   feat:课程结构调整
19
  import 'bloc/section_bloc.dart';
4b358e22   liangchengyou   feat:调整文件结构
20
  
37063ced   吴启风   feat:阶段选择指示器与阶段色联...
21
  /// 环节(课程)列表页
2187c85f   吴启风   feat:课程结构调整
22
  class SectionPage extends StatelessWidget {
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
23
    const SectionPage(
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
24
        {super.key, required this.courseUnitEntity, required this.courseUnitId});
8988aa69   liangchengyou   feat:首页+课程列表数据获取
25
  
2187c85f   吴启风   feat:课程结构调整
26
27
28
    final CourseUnitEntity courseUnitEntity;
  
    /// unitId
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
29
    final int courseUnitId;
95edef4f   liangchengyou   feat:更新适配代码
30
31
32
  
    @override
    Widget build(BuildContext context) {
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
33
34
35
      int initialPage = courseUnitEntity.courseUnitVOList
              ?.indexWhere((element) => element.id == courseUnitId) ??
          0;
60e47f7c   liangchengyou   feat:课程选择功能
36
      return BlocProvider(
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
37
38
39
40
41
        create: (context) => SectionBloc(
            courseUnitEntity,
            initialPage,
            PageController(initialPage: initialPage),
            ScrollController(),
5e2bbbd3   biao   添加音频
42
43
            ScrollController())
          ..add(InitEvent()),
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
44
        //为了触发指示器进入后计算位置
0cbdbb34   吴启风   feat:环节列表页返回单元列表页...
45
        //   ..add(CurrentUnitIndexChangeEvent(initialPage)),
2187c85f   吴启风   feat:课程结构调整
46
        child: _SectionPageView(context),
60e47f7c   liangchengyou   feat:课程选择功能
47
48
49
50
      );
    }
  }
  
2187c85f   吴启风   feat:课程结构调整
51
52
  class _SectionPageView extends StatelessWidget {
    const _SectionPageView(this.context);
454dc387   吴启风   feat:原阶段选择页(首页)增加...
53
54
55
  
    final BuildContext context;
  
60e47f7c   liangchengyou   feat:课程选择功能
56
57
    @override
    Widget build(BuildContext context) {
2187c85f   吴启风   feat:课程结构调整
58
      final bloc = BlocProvider.of<SectionBloc>(context);
0493c104   吴启风   feat:带音乐点击防抖函数优化
59
      final clickController = ClickWithMusicController.instance;
2187c85f   吴启风   feat:课程结构调整
60
      return BlocListener<SectionBloc, SectionState>(
523864dd   吴启风   feat:音频播放单例增加声明周期感知
61
        listener: (context, state) async {
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
62
          if (state is RequestEnterClassState) {
0493c104   吴启风   feat:带音乐点击防抖函数优化
63
64
65
66
67
68
69
            final courseType = state.courseType;
            final courseLessonId = state.courseLessonId;
            if (courseType == SectionType.song.value ||
                courseType == SectionType.video.value) {
              final title =
                  courseType == SectionType.song.value ? 'song' : 'video';
              final AudioPlayerUtilType audioType;
1e22b7d1   吴启风   feat:儿歌/视频环节接口请求时机优化
70
  
1e22b7d1   吴启风   feat:儿歌/视频环节接口请求时机优化
71
              ///儿歌/视频类型
0493c104   吴启风   feat:带音乐点击防抖函数优化
72
              if (courseType == SectionType.song.value) {
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
73
                audioType = AudioPlayerUtilType.musicTime;
82c8633c   biao   音频添加 页面优化
74
              } else {
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
75
                audioType = AudioPlayerUtilType.videoTime;
82c8633c   biao   音频添加 页面优化
76
              }
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
77
  
a0bbff8c   吴启风   feat:代码优化-背景音播放使用...
78
              await clickController.playMusicAndPerformAction(context, audioType,
0493c104   吴启风   feat:带音乐点击防抖函数优化
79
                  () async {
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
80
                ///播放音乐->调进入课程接口->跳转课程页面
0493c104   吴启风   feat:带音乐点击防抖函数优化
81
                await bloc.requestEnterClass(courseLessonId, () {
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
82
83
84
                  pushNamed(AppRouteName.lookVideo, arguments: {
                    'videoUrl': null,
                    'title': title,
0493c104   吴启风   feat:带音乐点击防抖函数优化
85
                    'courseLessonId': courseLessonId,
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
86
87
                    'isTopic': true
                  }).then((value) {
c272c662   吴启风   fix: 崩溃修复
88
                    if (value != null && !bloc.isClosed) {
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
89
90
                      Map<String, dynamic> dataMap =
                          value as Map<String, dynamic>;
c272c662   吴启风   fix: 崩溃修复
91
92
93
94
95
96
97
98
                      try {
                        bloc.add(RequestEndClassEvent(
                            dataMap['courseLessonId']!, dataMap['isCompleted'],
                            currentTime: dataMap['currentTime'],
                            autoNextSection: dataMap['nextSection']));
                      } catch (e) {
                        print('BLoC add event error: $e');
                      }
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
99
100
101
102
                    }
                    AudioPlayerUtil.getInstance()
                        .playAudio(AudioPlayerUtilType.countWithMe);
                  });
0493c104   吴启风   feat:带音乐点击防抖函数优化
103
                }, onRequestEnterFailed: (error) {
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
104
                });
1e22b7d1   吴启风   feat:儿歌/视频环节接口请求时机优化
105
              });
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
106
107
108
              return;
            }
  
0493c104   吴启风   feat:带音乐点击防抖函数优化
109
            if (courseType == SectionType.pictureBook.value) {
523864dd   吴启风   feat:音频播放单例增加声明周期感知
110
              //绘本
a0bbff8c   吴启风   feat:代码优化-背景音播放使用...
111
              await clickController.playMusicAndPerformAction(
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
112
                  context, AudioPlayerUtilType.readingTime, () async {
0493c104   吴启风   feat:带音乐点击防抖函数优化
113
                await bloc.requestEnterClass(courseLessonId, () {
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
114
115
116
117
                  pushNamed(AppRouteName.reading, arguments: {
                    'courseLessonId': courseLessonId,
                    'moduleColor': ModuleCache.instance.getCurrentThemeColor()
                  }).then((value) {
c272c662   吴启风   fix: 崩溃修复
118
                    if (value != null && !bloc.isClosed) {
0493c104   吴启风   feat:带音乐点击防抖函数优化
119
120
                      Map<String, dynamic> dataMap =
                          value as Map<String, dynamic>;
c272c662   吴启风   fix: 崩溃修复
121
122
123
124
125
126
127
128
129
130
                      try {
                        bloc.add(RequestEndClassEvent(
                          dataMap['courseLessonId']!,
                          dataMap['isCompleted'],
                          currentStep: dataMap['currentStep'],
                          autoNextSection: dataMap['nextSection'],
                        ));
                      } catch (e) {
                        print('BLoC add event error: $e');
                      }
0493c104   吴启风   feat:带音乐点击防抖函数优化
131
132
133
134
                      AudioPlayerUtil.getInstance()
                          .playAudio(AudioPlayerUtilType.countWithMe);
                    }
                  });
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
135
                });
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
136
              });
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
137
138
139
              return;
            }
  
0493c104   吴启风   feat:带音乐点击防抖函数优化
140
            if (courseType == SectionType.practice.value) {
2187c85f   吴启风   feat:课程结构调整
141
              //练习
a0bbff8c   吴启风   feat:代码优化-背景音播放使用...
142
              await clickController.playMusicAndPerformAction(
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
143
                  context, AudioPlayerUtilType.quizTime, () async {
0493c104   吴启风   feat:带音乐点击防抖函数优化
144
                await bloc.requestEnterClass(courseLessonId, () {
07b173c9   吴启风   feat:练习页上方进度信息改成进...
145
146
                  pushNamed(AppRouteName.topicPic, arguments: {
                    'courseLessonId': courseLessonId,
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
147
                    'moduleColor': ModuleCache.instance.getCurrentThemeColor()
07b173c9   吴启风   feat:练习页上方进度信息改成进...
148
                  }).then((value) {
c272c662   吴启风   fix: 崩溃修复
149
                    if (value != null && !bloc.isClosed) {
0493c104   吴启风   feat:带音乐点击防抖函数优化
150
151
                      Map<String, dynamic> dataMap =
                          value as Map<String, dynamic>;
c272c662   吴启风   fix: 崩溃修复
152
153
154
155
156
157
158
159
                      try {
                        bloc.add(RequestEndClassEvent(
                            dataMap['courseLessonId']!, dataMap['isCompleted'],
                            currentStep: dataMap['currentStep'],
                            autoNextSection: dataMap['nextSection']));
                      } catch (e) {
                        print('BLoC add event error: $e');
                      }
0493c104   吴启风   feat:带音乐点击防抖函数优化
160
161
162
163
                    }
                    AudioPlayerUtil.getInstance()
                        .playAudio(AudioPlayerUtilType.countWithMe);
                  });
cd32eb01   吴启风   feat:播放音乐防抖处理(课程环节页)
164
                });
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
165
              });
3c1d5c64   liangchengyou   feat:练习功能完成
166
167
              return;
            }
3c1d5c64   liangchengyou   feat:练习功能完成
168
169
          }
        },
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
170
        child: _sectionView(),
95edef4f   liangchengyou   feat:更新适配代码
171
172
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
173
  
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
174
    Widget _sectionView() =>
2187c85f   吴启风   feat:课程结构调整
175
176
        BlocBuilder<SectionBloc, SectionState>(builder: (context, state) {
          final bloc = BlocProvider.of<SectionBloc>(context);
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
177
178
179
180
181
182
183
          return Scaffold(
            body: Container(
              color: Colors.white,
              child: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
2187c85f   吴启风   feat:课程结构调整
184
                    SectionHeaderWidget(
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
185
                        title: bloc.getCourseUnitDetail().name,
0cbdbb34   吴启风   feat:环节列表页返回单元列表页...
186
187
188
189
190
                        onBack: () {
                          popPage(data: {
                            'needRefresh': bloc.courseUnitEntityChanged,
                          });
                        }),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
191
                    Expanded(
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
192
193
                        child: Padding(
                      padding: EdgeInsets.symmetric(horizontal: 10.w),
b816d5d6   吴启风   feat:去除嵌套滑动,解决滑快了...
194
                      child: PageView.builder(
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
195
196
197
                          itemCount: bloc.unlockPageCount(),
                          controller: bloc.pageController,
                          onPageChanged: (int index) {
c272c662   吴启风   fix: 崩溃修复
198
199
200
                            if (!bloc.isClosed) {
                              bloc.add(CurrentUnitIndexChangeEvent(index));
                            }
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
201
202
203
204
205
206
207
208
209
210
211
212
213
                          },
                          itemBuilder: (context, index) {
                            return ScrollConfiguration(
                              ///去掉 Android 上默认的边缘拖拽效果
                              behavior: ScrollConfiguration.of(context)
                                  .copyWith(overscroll: false),
                              child: _itemTransCard(
                                  bloc.getCourseUnitDetail(pageIndex: index),
                                  index,
                                  context),
                            );
                          }),
                    )),
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
214
                    SafeArea(
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
215
216
217
218
219
220
221
222
223
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
264
265
266
                      child: SizedBox(
                          width: 210.w,
                          height: 40.h,
                          // child: OverflowBox(
                          //   maxWidth: 300, // 允许内容超出容器宽度
                          child: ListView.builder(
                              controller: bloc.indicatorSrollController,
                              scrollDirection: Axis.horizontal,
                              itemCount: bloc.unlockPageCount(),
                              itemBuilder: (context, index) {
                                bool isSelected = index == bloc.currentPage;
                                // 计算透明度,使得当前页的指示器不透明,两侧逐渐透明
                                double opacity = 0.25 +
                                    (1 - ((bloc.currentPage - index).abs() / 2)) *
                                        0.5;
                                // 限制透明度在 0.5 到 1.0 之间
                                opacity = opacity.clamp(0.25, 1.0);
                                return GestureDetector(
                                  onTap: () => bloc.pageController.animateToPage(
                                      index,
                                      duration: const Duration(milliseconds: 60),
                                      curve: Curves.ease),
                                  child: SizedBox(
                                    width: 30.0.w,
                                    height: 30.0.h,
                                    child: Padding(
                                      padding:
                                          EdgeInsets.all(isSelected ? 0.w : 5.w),
                                      child: Opacity(
                                        opacity: opacity,
                                        child: Container(
                                          alignment: Alignment.center,
                                          decoration: BoxDecoration(
                                            color: isSelected
                                                ? Colors.blue
                                                : Colors.grey,
                                            shape: BoxShape.circle,
                                          ),
                                          child: Text("${index + 1}",
                                              textAlign: TextAlign.center,
                                              style: TextStyle(
                                                  color: Colors.white,
                                                  fontSize:
                                                      isSelected ? 12.sp : 8.sp)),
                                        ),
                                      ),
                                    ),
                                  ),
                                );
                              })),
                    ),
                    // )
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
267
268
269
                  ],
                ),
              ),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
270
            ),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
271
272
          );
        });
056970d8   Key   feat: api
273
  }
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
274
  
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
275
276
  Widget _itemTransCard(
      CourseUnitDetail courseUnitDetail, int pageIndex, BuildContext context) {
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
277
    final bloc = BlocProvider.of<SectionBloc>(context);
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
    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(
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
293
                color: ModuleCache.instance.getCurrentThemeColor()),
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
294
295
296
297
298
            // 加载动画
          ],
        ),
      );
    } else {
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
      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:环节页增加翻页切换单元效果
316
  
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
                  ///进入课堂
                  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:环节页增加翻页切换单元效果
336
  
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
337
338
339
340
341
                  ///进入课堂
                  bloc.add(RequestEnterClassEvent(
                      sectionData.id.toString(), sectionData.courseType));
                },
                child: SectionItem(
8df5fbf9   吴启风   feat:单元列表页由于ios嵌套...
342
343
344
345
346
                  lessons: sectionData,
                ),
              );
            }
          });
66a7e3e7   吴启风   feat:退出课堂和结束课堂优化
347
    }
3ba925a9   吴启风   feat:环节页增加翻页切换单元效果
348
  }