Blame view

lib/pages/section/section_page.dart 9.03 KB
95edef4f   liangchengyou   feat:更新适配代码
1
  import 'package:flutter/material.dart';
60e47f7c   liangchengyou   feat:课程选择功能
2
  import 'package:flutter_bloc/flutter_bloc.dart';
d35a4e87   liangchengyou   feat:磨耳朵功能UI
3
  import 'package:flutter_screenutil/flutter_screenutil.dart';
f5fc01c1   liangchengyou   feat:修复首页进入个人信息页闪退问题
4
  import 'package:wow_english/common/core/user_util.dart';
d35a4e87   liangchengyou   feat:磨耳朵功能UI
5
  import 'package:wow_english/common/extension/string_extension.dart';
2187c85f   吴启风   feat:课程结构调整
6
7
8
9
  import 'package:wow_english/models/course_unit_entity.dart';
  import 'package:wow_english/pages/section/widgets/home_video_item.dart';
  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:课程选择功能
10
  import 'package:wow_english/route/route.dart';
c61b3c1a   Key   feat: toast_util....
11
  import 'package:wow_english/utils/toast_util.dart';
95edef4f   liangchengyou   feat:更新适配代码
12
  
2187c85f   吴启风   feat:课程结构调整
13
14
  import '../../models/course_section_entity.dart';
  import 'bloc/section_bloc.dart';
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
15
  import 'courese_module_model.dart';
4b358e22   liangchengyou   feat:调整文件结构
16
  
2187c85f   吴启风   feat:课程结构调整
17
18
19
  /// 环节列表页
  class SectionPage extends StatelessWidget {
    const SectionPage({super.key, required this.courseUnitEntity, required this.courseUnitDetail});
8988aa69   liangchengyou   feat:首页+课程列表数据获取
20
  
2187c85f   吴启风   feat:课程结构调整
21
22
23
24
    final CourseUnitEntity courseUnitEntity;
  
    /// unitId
    final CourseUnitDetail courseUnitDetail;
95edef4f   liangchengyou   feat:更新适配代码
25
26
27
  
    @override
    Widget build(BuildContext context) {
60e47f7c   liangchengyou   feat:课程选择功能
28
      return BlocProvider(
2187c85f   吴启风   feat:课程结构调整
29
30
        create: (context) => SectionBloc(courseUnitEntity, courseUnitDetail)..add(RequestDataEvent()),
        child: _SectionPageView(context),
60e47f7c   liangchengyou   feat:课程选择功能
31
32
33
34
      );
    }
  }
  
2187c85f   吴启风   feat:课程结构调整
35
36
  class _SectionPageView extends StatelessWidget {
    const _SectionPageView(this.context);
454dc387   吴启风   feat:原阶段选择页(首页)增加...
37
38
39
  
    final BuildContext context;
  
60e47f7c   liangchengyou   feat:课程选择功能
40
41
    @override
    Widget build(BuildContext context) {
2187c85f   吴启风   feat:课程结构调整
42
43
      final bloc = BlocProvider.of<SectionBloc>(context);
      return BlocListener<SectionBloc, SectionState>(
3c1d5c64   liangchengyou   feat:练习功能完成
44
45
        listener: (context, state) {
          if (state is RequestVideoLessonState) {
2187c85f   吴启风   feat:课程结构调整
46
            final videoUrl = bloc.processEntity?.videos?.videoUrl ?? '';
3c1d5c64   liangchengyou   feat:练习功能完成
47
48
49
50
51
52
53
54
55
56
57
58
            var title = '';
            if (state.type == 1) {
              title = 'song';
            }
  
            if (state.type == 2) {
              title = 'video';
            }
  
            if (state.type == 5) {
              title = 'bonus';
            }
997ea0d6   liangchengyou   feat:绘本闪退问题修复
59
  
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
60
61
62
            if (videoUrl.isEmpty || !videoUrl.contains('http')) {
              return;
            }
2187c85f   吴启风   feat:课程结构调整
63
64
65
66
67
            pushNamed(AppRouteName.lookVideo, arguments: {
              'videoUrl': videoUrl,
              'title': title,
              'courseLessonId': state.courseLessonId
            }).then((value) {
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
68
              if (value != null) {
2187c85f   吴启风   feat:课程结构调整
69
                Map<String, String> dataMap = value as Map<String, String>;
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
70
71
72
73
74
75
76
77
78
79
80
                bloc.add(RequestExitClassEvent(
                  dataMap['courseLessonId']!,
                  '0',
                  dataMap['currentTime']!,
                ));
              }
            });
            return;
          }
  
          if (state is RequestEnterClassState) {
2187c85f   吴启风   feat:课程结构调整
81
82
            if (state.courseType != 3 && state.courseType != 4) {
              ///视频类型
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
83
              ///获取视频课程内容
2187c85f   吴启风   feat:课程结构调整
84
85
              bloc.add(RequestVideoLessonEvent(
                  state.courseLessonId, state.courseType));
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
86
87
88
              return;
            }
  
2187c85f   吴启风   feat:课程结构调整
89
90
91
92
93
            if (state.courseType == 4) {
              //绘本
              pushNamed(AppRouteName.reading,
                      arguments: {'courseLessonId': state.courseLessonId})
                  .then((value) {
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
94
                if (value != null) {
2187c85f   吴启风   feat:课程结构调整
95
                  Map<String, String> dataMap = value as Map<String, String>;
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
96
                  bloc.add(RequestExitClassEvent(
2187c85f   吴启风   feat:课程结构调整
97
                      dataMap['courseLessonId']!, dataMap['currentStep']!, '0'));
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
98
99
100
101
102
                }
              });
              return;
            }
  
2187c85f   吴启风   feat:课程结构调整
103
104
105
106
107
            if (state.courseType == 3) {
              //练习
              pushNamed(AppRouteName.topicPic,
                      arguments: {'courseLessonId': state.courseLessonId})
                  .then((value) {
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
108
                if (value != null) {
2187c85f   吴启风   feat:课程结构调整
109
                  Map<String, String> dataMap = value as Map<String, String>;
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
110
                  bloc.add(RequestExitClassEvent(
2187c85f   吴启风   feat:课程结构调整
111
                      dataMap['courseLessonId']!, dataMap['currentStep']!, '0'));
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
112
113
                }
              });
3c1d5c64   liangchengyou   feat:练习功能完成
114
115
              return;
            }
3c1d5c64   liangchengyou   feat:练习功能完成
116
117
          }
        },
d35a4e87   liangchengyou   feat:磨耳朵功能UI
118
        child: _homeView(),
95edef4f   liangchengyou   feat:更新适配代码
119
120
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
121
  
2187c85f   吴启风   feat:课程结构调整
122
123
124
    Widget _homeView() =>
        BlocBuilder<SectionBloc, SectionState>(builder: (context, state) {
          final bloc = BlocProvider.of<SectionBloc>(context);
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
125
126
127
128
129
130
131
          return Scaffold(
            body: Container(
              color: Colors.white,
              child: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
2187c85f   吴启风   feat:课程结构调整
132
133
134
                    SectionHeaderWidget(
                        title: bloc.courseUnitDetail.name,
                        courseModuleCode: bloc.courseUnitEntity.courseModuleCode),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
135
136
                    Expanded(
                        child: ListView.builder(
2187c85f   吴启风   feat:课程结构调整
137
                            itemCount: bloc.courseSectionDatas?.length ?? 0,
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
138
139
                            scrollDirection: Axis.horizontal,
                            itemBuilder: (BuildContext context, int index) {
2187c85f   吴启风   feat:课程结构调整
140
141
142
                              CourseSectionEntity sectionData =
                                  bloc.courseSectionDatas![index];
                              if (sectionData.courseType == 5) {
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
143
144
145
                                //彩蛋
                                return GestureDetector(
                                  onTap: () {
278208b8   吴启风   feat:1、用户访问权限调整;2...
146
                                    if (!UserUtil.isLogined()) {
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
147
148
149
                                      pushNamed(AppRouteName.login);
                                      return;
                                    }
2187c85f   吴启风   feat:课程结构调整
150
                                    if (sectionData.lock == true) {
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
151
152
153
                                      showToast('当前课程暂未解锁');
                                      return;
                                    }
2187c85f   吴启风   feat:课程结构调整
154
  
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
155
                                    ///进入课堂
2187c85f   吴启风   feat:课程结构调整
156
157
                                    bloc.add(RequestEnterClassEvent(
                                        sectionData.id.toString(), sectionData.courseType));
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
158
                                  },
2187c85f   吴启风   feat:课程结构调整
159
160
                                  child: SectionBoundsItem(
                                    imageUrl: sectionData.coverUrl,
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
161
162
163
164
165
                                  ),
                                );
                              } else {
                                return GestureDetector(
                                  onTap: () {
278208b8   吴启风   feat:1、用户访问权限调整;2...
166
                                    if (!UserUtil.isLogined()) {
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
167
168
169
                                      pushNamed(AppRouteName.login);
                                      return;
                                    }
2187c85f   吴启风   feat:课程结构调整
170
                                    if (sectionData.lock == true) {
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
171
172
173
                                      showToast('当前课程暂未解锁');
                                      return;
                                    }
2187c85f   吴启风   feat:课程结构调整
174
  
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
175
                                    ///进入课堂
2187c85f   吴启风   feat:课程结构调整
176
177
                                    bloc.add(RequestEnterClassEvent(
                                        sectionData.id.toString(), sectionData.courseType));
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
178
                                  },
2187c85f   吴启风   feat:课程结构调整
179
180
181
                                  child: SectionVideoItem(
                                    unitEntity: bloc.courseUnitEntity,
                                    lessons: sectionData,
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
182
183
184
185
                                  ),
                                );
                              }
                            })),
1748f1e6   吴启风   feat:隐藏环节页底部页码
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
213
214
215
216
217
218
219
220
221
222
223
224
225
                    // 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.courseUnitEntity.nowStep ?? 0)}/${bloc.courseUnitEntity.total ?? 0}',
                    //             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:首页主题颜色+已知问题修改
226
227
228
                  ],
                ),
              ),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
229
            ),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
230
231
          );
        });
056970d8   Key   feat: api
232
  }