Blame view

lib/pages/home/home_page.dart 7.05 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';
8988aa69   liangchengyou   feat:首页+课程列表数据获取
9
  import 'package:wow_english/pages/home/widgets/home_vidoe_item.dart';
60e47f7c   liangchengyou   feat:课程选择功能
10
  import 'package:wow_english/route/route.dart';
e5c9e98f   liangchengyou   feat:首页模块颜色
11
  import 'package:wow_english/utils/color_util.dart';
c61b3c1a   Key   feat: toast_util....
12
  import 'package:wow_english/utils/toast_util.dart';
95edef4f   liangchengyou   feat:更新适配代码
13
  
4b358e22   liangchengyou   feat:调整文件结构
14
15
  import 'bloc/home_bloc.dart';
  
95edef4f   liangchengyou   feat:更新适配代码
16
  class HomePage extends StatelessWidget {
8988aa69   liangchengyou   feat:首页+课程列表数据获取
17
18
19
20
    const HomePage({super.key, this.moduleId});
  
    /// 模块id
    final String? 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()),
60e47f7c   liangchengyou   feat:课程选择功能
26
27
28
29
30
31
32
33
        child: _HomePageView(),
      );
    }
  }
  
  class _HomePageView extends StatelessWidget {
    void _headerActionEvent(HeaderActionType type) {
      if (type == HeaderActionType.video) {
08a0f5a8   liangchengyou   feat:路由方式更新
34
        pushNamed(AppRouteName.reAfter);
60e47f7c   liangchengyou   feat:课程选择功能
35
      } else if (type == HeaderActionType.phase) {
08a0f5a8   liangchengyou   feat:路由方式更新
36
        pushNamed(AppRouteName.lesson);
60e47f7c   liangchengyou   feat:课程选择功能
37
      } else if (type == HeaderActionType.listen) {
08a0f5a8   liangchengyou   feat:路由方式更新
38
        pushNamed(AppRouteName.listen);
d35a4e87   liangchengyou   feat:磨耳朵功能UI
39
      } else if (type == HeaderActionType.shop) {
08a0f5a8   liangchengyou   feat:路由方式更新
40
        pushNamed(AppRouteName.shop);
056970d8   Key   feat: api
41
      } else if (type == HeaderActionType.user) {
71fb0fb2   liangchengyou   feat:首页未登陆状态下逻辑调整
42
        debugPrint(UserUtil.token);
f5fc01c1   liangchengyou   feat:修复首页进入个人信息页闪退问题
43
44
45
46
47
        if(UserUtil.token.isEmpty) {
          pushNamed(AppRouteName.login);
        } else {
          pushNamed(AppRouteName.user);
        }
60e47f7c   liangchengyou   feat:课程选择功能
48
      } else {
608c05b4   liangchengyou   feat:兑换课程
49
  
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
73
  
            if (videoUrl.isEmpty && !videoUrl.contains('http')) {
3c1d5c64   liangchengyou   feat:练习功能完成
74
75
              return;
            }
08a0f5a8   liangchengyou   feat:路由方式更新
76
            pushNamed(AppRouteName.lookVideo,arguments: {'videoUrl':videoUrl,'title':title});
3c1d5c64   liangchengyou   feat:练习功能完成
77
78
          }
        },
d35a4e87   liangchengyou   feat:磨耳朵功能UI
79
        child: _homeView(),
95edef4f   liangchengyou   feat:更新适配代码
80
81
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
82
  
c61b3c1a   Key   feat: toast_util....
83
    Widget _homeView() => BlocBuilder<HomeBloc, HomeState>(builder: (context, state) {
08a0f5a8   liangchengyou   feat:路由方式更新
84
85
86
87
88
89
90
91
92
      final bloc = BlocProvider.of<HomeBloc>(context);
      return Scaffold(
        body: Container(
          color: Colors.white,
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                HomeTabHeaderWidget(
e5c9e98f   liangchengyou   feat:首页模块颜色
93
                  themColor: bloc.modelData?.courseModuleThemeColor,
08a0f5a8   liangchengyou   feat:路由方式更新
94
95
96
97
98
99
                  actionTap: (HeaderActionType type) {
                    _headerActionEvent(type);
                  },
                ),
                Expanded(
                    child: ListView.builder(
e5c9e98f   liangchengyou   feat:首页模块颜色
100
                        itemCount: bloc.modelData?.totalCourseLesson??0,
08a0f5a8   liangchengyou   feat:路由方式更新
101
102
103
104
105
106
107
                        scrollDirection: Axis.horizontal,
                        itemBuilder: (BuildContext context, int index) {
                          CourseCourseLessons? data = bloc.modelData?.courseLessons?[index];
                          if (data?.courseType == 5) {
                            //彩蛋
                            return GestureDetector(
                              onTap: () {
71fb0fb2   liangchengyou   feat:首页未登陆状态下逻辑调整
108
109
110
111
                                if(UserUtil.token.isEmpty) {
                                  pushNamed(AppRouteName.login);
                                  return;
                                }
08a0f5a8   liangchengyou   feat:路由方式更新
112
113
114
115
116
117
118
119
120
121
122
123
124
                                if (data!.lock!) {
                                  showToast('当前课程暂未解锁');
                                  return;
                                }
                                bloc.add(RequestVideoLessonEvent(data.id!,data.courseType!));
                              },
                              child: HomeBoundsItem(
                                imageUrl: data?.coverUrl,
                              ),
                            );
                          } else {
                            return GestureDetector(
                              onTap: () {
71fb0fb2   liangchengyou   feat:首页未登陆状态下逻辑调整
125
126
127
128
                                if(UserUtil.token.isEmpty) {
                                  pushNamed(AppRouteName.login);
                                  return;
                                }
08a0f5a8   liangchengyou   feat:路由方式更新
129
130
131
132
133
                                if (data!.lock!) {
                                  showToast('当前课程暂未解锁');
                                  return;
                                }
                                if (data.courseType == 4) {//绘本
53e9e6db   吴启风   feat:绘本语音评测逻辑
134
                                  Navigator.of(context).pushNamed(AppRouteName.reading, arguments: {'courseLessonId':data.id!});
08a0f5a8   liangchengyou   feat:路由方式更新
135
136
                                  return;
                                }
608c05b4   liangchengyou   feat:兑换课程
137
  
08a0f5a8   liangchengyou   feat:路由方式更新
138
139
140
141
                                if (data.courseType == 3) {//练习
                                  Navigator.of(context).pushNamed(AppRouteName.topicPic,arguments: {'courseLessonId':data.id!});
                                  return;
                                }
3c1d5c64   liangchengyou   feat:练习功能完成
142
  
08a0f5a8   liangchengyou   feat:路由方式更新
143
144
145
146
                                //儿歌/看视频
                                bloc.add(RequestVideoLessonEvent(data.id!,data.courseType!));
                              },
                              child: HomeVideoItem(
e5c9e98f   liangchengyou   feat:首页模块颜色
147
                                themColor: bloc.modelData?.courseModuleThemeColor,
08a0f5a8   liangchengyou   feat:路由方式更新
148
                                lessons: data,
d35a4e87   liangchengyou   feat:磨耳朵功能UI
149
                              ),
08a0f5a8   liangchengyou   feat:路由方式更新
150
151
152
153
154
155
156
157
158
159
160
161
                            );
                          }
                        })),
                SafeArea(
                  child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: 13.w),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        SizedBox(
                          height: 47.h,
                          width: 80.w,
d35a4e87   liangchengyou   feat:磨耳朵功能UI
162
                        ),
08a0f5a8   liangchengyou   feat:路由方式更新
163
164
                        Container(
                          decoration: BoxDecoration(
e5c9e98f   liangchengyou   feat:首页模块颜色
165
                            color: HexColor(bloc.modelData?.courseModuleThemeColor??''),
08a0f5a8   liangchengyou   feat:路由方式更新
166
167
168
169
                            borderRadius: BorderRadius.circular(14.5.r),
                          ),
                          padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 24.w),
                          child: Text(
e5c9e98f   liangchengyou   feat:首页模块颜色
170
                            '${(bloc.modelData?.nowCourseLesson??0)}/${bloc.modelData?.totalCourseLesson??0}',
08a0f5a8   liangchengyou   feat:路由方式更新
171
172
173
174
175
176
177
178
179
180
181
182
183
184
                            style: TextStyle(color: Colors.white, fontSize: 12.sp),
                          ),
                        ),
                        Image.asset(
                          'blue-positive'.assetPng,
                          height: 47.h,
                          width: 80.w,
                          // color: Colors.red,
                        ),
                      ],
                    ),
                  ),
                )
              ],
d35a4e87   liangchengyou   feat:磨耳朵功能UI
185
            ),
08a0f5a8   liangchengyou   feat:路由方式更新
186
187
188
189
          ),
        ),
      );
    });
056970d8   Key   feat: api
190
  }