Blame view

lib/pages/home/home_page.dart 8.63 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';
8988aa69   liangchengyou   feat:首页+课程列表数据获取
6
7
  import 'package:wow_english/models/course_entity.dart';
  import 'package:wow_english/pages/home/widgets/home_bouns_item.dart';
4b358e22   liangchengyou   feat:调整文件结构
8
  import 'package:wow_english/pages/home/widgets/home_tab_header_widget.dart';
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
9
  import 'package:wow_english/pages/home/widgets/home_video_item.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
  
4b358e22   liangchengyou   feat:调整文件结构
13
  import 'bloc/home_bloc.dart';
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
14
  import 'courese_module_model.dart';
4b358e22   liangchengyou   feat:调整文件结构
15
  
95edef4f   liangchengyou   feat:更新适配代码
16
  class HomePage extends StatelessWidget {
8988aa69   liangchengyou   feat:首页+课程列表数据获取
17
18
19
    const HomePage({super.key, this.moduleId});
  
    /// 模块id
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
20
    final int? moduleId;
95edef4f   liangchengyou   feat:更新适配代码
21
22
23
  
    @override
    Widget build(BuildContext context) {
60e47f7c   liangchengyou   feat:课程选择功能
24
      return BlocProvider(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
25
        create: (context) => HomeBloc(moduleId)..add(RequestDataEvent()),
454dc387   吴启风   feat:原阶段选择页(首页)增加...
26
        child: _HomePageView(context),
60e47f7c   liangchengyou   feat:课程选择功能
27
28
29
30
31
      );
    }
  }
  
  class _HomePageView extends StatelessWidget {
454dc387   吴启风   feat:原阶段选择页(首页)增加...
32
33
34
35
36
  
    const _HomePageView(this.context);
  
    final BuildContext context;
  
60e47f7c   liangchengyou   feat:课程选择功能
37
38
    void _headerActionEvent(HeaderActionType type) {
      if (type == HeaderActionType.video) {
08a0f5a8   liangchengyou   feat:路由方式更新
39
        pushNamed(AppRouteName.reAfter);
60e47f7c   liangchengyou   feat:课程选择功能
40
      } else if (type == HeaderActionType.phase) {
454dc387   吴启风   feat:原阶段选择页(首页)增加...
41
        pushNamed(AppRouteName.lesson);
60e47f7c   liangchengyou   feat:课程选择功能
42
      } else if (type == HeaderActionType.listen) {
08a0f5a8   liangchengyou   feat:路由方式更新
43
        pushNamed(AppRouteName.listen);
d35a4e87   liangchengyou   feat:磨耳朵功能UI
44
      } else if (type == HeaderActionType.shop) {
08a0f5a8   liangchengyou   feat:路由方式更新
45
        pushNamed(AppRouteName.shop);
056970d8   Key   feat: api
46
      } else if (type == HeaderActionType.user) {
454dc387   吴启风   feat:原阶段选择页(首页)增加...
47
48
49
        pushNamed(AppRouteName.user);
      } else if (type == HeaderActionType.home) {
        Navigator.pop(context);
60e47f7c   liangchengyou   feat:课程选择功能
50
51
52
53
54
      }
    }
  
    @override
    Widget build(BuildContext context) {
3c1d5c64   liangchengyou   feat:练习功能完成
55
      final bloc = BlocProvider.of<HomeBloc>(context);
c61b3c1a   Key   feat: toast_util....
56
      return BlocListener<HomeBloc, HomeState>(
3c1d5c64   liangchengyou   feat:练习功能完成
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        listener: (context, state) {
          if (state is RequestVideoLessonState) {
            final videoUrl = bloc.processEntity?.videos?.videoUrl??'';
            var title = '';
            if (state.type == 1) {
              title = 'song';
            }
  
            if (state.type == 2) {
              title = 'video';
            }
  
            if (state.type == 5) {
              title = 'bonus';
            }
997ea0d6   liangchengyou   feat:绘本闪退问题修复
72
  
934e2b47   liangchengyou   feat:权限调整+课程进度接口对接
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
            if (videoUrl.isEmpty || !videoUrl.contains('http')) {
              return;
            }
            pushNamed(AppRouteName.lookVideo,arguments: {'videoUrl':videoUrl,'title':title,'courseLessonId':state.courseLessonId}).then((value) {
              if (value != null) {
                Map<String,String> dataMap = value as Map<String,String>;
                bloc.add(RequestExitClassEvent(
                  dataMap['courseLessonId']!,
                  '0',
                  dataMap['currentTime']!,
                ));
              }
            });
            return;
          }
  
          if (state is RequestEnterClassState) {
            if (state.courseType != 3 && state.courseType != 4) {///视频类型
              ///获取视频课程内容
              bloc.add(RequestVideoLessonEvent(state.courseLessonId,state.courseType));
              return;
            }
  
            if (state.courseType == 4) {//绘本
              pushNamed(AppRouteName.reading, arguments: {'courseLessonId':state.courseLessonId}).then((value) {
                if (value != null) {
                  Map<String,String> dataMap = value as Map<String,String>;
                  bloc.add(RequestExitClassEvent(
                      dataMap['courseLessonId']!,
                      dataMap['currentStep']!,
                      '0'
                  ));
                }
              });
              return;
            }
  
            if (state.courseType == 3) {//练习
              pushNamed(AppRouteName.topicPic,arguments: {'courseLessonId':state.courseLessonId}).then((value) {
                if (value != null) {
                  Map<String,String> dataMap = value as Map<String,String>;
                  bloc.add(RequestExitClassEvent(
                      dataMap['courseLessonId']!,
                      dataMap['currentStep']!,
                      '0'
                  ));
                }
              });
3c1d5c64   liangchengyou   feat:练习功能完成
121
122
              return;
            }
3c1d5c64   liangchengyou   feat:练习功能完成
123
124
          }
        },
d35a4e87   liangchengyou   feat:磨耳朵功能UI
125
        child: _homeView(),
95edef4f   liangchengyou   feat:更新适配代码
126
127
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
128
  
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    Widget _homeView() => BlocBuilder<HomeBloc, HomeState>(
        builder: (context, state) {
          final bloc = BlocProvider.of<HomeBloc>(context);
          return Scaffold(
            body: Container(
              color: Colors.white,
              child: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    HomeTabHeaderWidget(
                      entity: bloc.modelData,
                      actionTap: (HeaderActionType type) {
                        _headerActionEvent(type);
                      },
                    ),
                    Expanded(
                        child: ListView.builder(
                            itemCount: bloc.modelData?.totalCourseLesson??0,
                            scrollDirection: Axis.horizontal,
                            itemBuilder: (BuildContext context, int index) {
                              CourseCourseLessons? data = bloc.modelData?.courseLessons?[index];
                              if (data?.courseType == 5) {
                                //彩蛋
                                return GestureDetector(
                                  onTap: () {
278208b8   吴启风   feat:1、用户访问权限调整;2...
155
                                    if (!UserUtil.isLogined()) {
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
                                      pushNamed(AppRouteName.login);
                                      return;
                                    }
                                    if (data!.lock!) {
                                      showToast('当前课程暂未解锁');
                                      return;
                                    }
                                    ///进入课堂
                                    bloc.add(RequestEnterClassEvent(data.id!,data.courseType!));
                                  },
                                  child: HomeBoundsItem(
                                    imageUrl: data?.coverUrl,
                                  ),
                                );
                              } else {
                                return GestureDetector(
                                  onTap: () {
278208b8   吴启风   feat:1、用户访问权限调整;2...
173
                                    if (!UserUtil.isLogined()) {
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
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
                                      pushNamed(AppRouteName.login);
                                      return;
                                    }
                                    if (data!.lock!) {
                                      showToast('当前课程暂未解锁');
                                      return;
                                    }
                                    ///进入课堂
                                    bloc.add(RequestEnterClassEvent(data.id!,data.courseType!));
                                  },
                                  child: HomeVideoItem(
                                    entity: bloc.modelData,
                                    lessons: data,
                                  ),
                                );
                              }
                            })),
                    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.modelData?.courseModuleCode??'Phase-1').color,
                                borderRadius: BorderRadius.circular(14.5.r),
08a0f5a8   liangchengyou   feat:路由方式更新
205
                              ),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
206
207
208
209
                              padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 24.w),
                              child: Text(
                                '${(bloc.modelData?.nowCourseLesson??0)}/${bloc.modelData?.totalCourseLesson??0}',
                                style: TextStyle(color: Colors.white, fontSize: 12.sp),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
210
                              ),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
211
212
213
214
215
216
217
218
                            ),
                            Image.asset(
                              CourseModuleModel(bloc.modelData?.courseModuleCode??'Phase-1').courseModuleLogo.assetPng,
                              height: 47.h,
                              width: 80.w,
                              // color: Colors.red,
                            ),
                          ],
08a0f5a8   liangchengyou   feat:路由方式更新
219
                        ),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
220
221
222
223
224
                      ),
                    )
                  ],
                ),
              ),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
225
            ),
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
226
227
          );
        });
056970d8   Key   feat: api
228
  }