Blame view

lib/pages/home/home_page.dart 6.2 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
4
  import 'package:flutter_screenutil/flutter_screenutil.dart';
  import 'package:wow_english/common/extension/string_extension.dart';
8988aa69   liangchengyou   feat:首页+课程列表数据获取
5
6
  import 'package:wow_english/models/course_entity.dart';
  import 'package:wow_english/pages/home/widgets/home_bouns_item.dart';
4b358e22   liangchengyou   feat:调整文件结构
7
  import 'package:wow_english/pages/home/widgets/home_tab_header_widget.dart';
8988aa69   liangchengyou   feat:首页+课程列表数据获取
8
  import 'package:wow_english/pages/home/widgets/home_vidoe_item.dart';
60e47f7c   liangchengyou   feat:课程选择功能
9
  import 'package:wow_english/route/route.dart';
c61b3c1a   Key   feat: toast_util....
10
  import 'package:wow_english/utils/toast_util.dart';
95edef4f   liangchengyou   feat:更新适配代码
11
  
4b358e22   liangchengyou   feat:调整文件结构
12
13
  import 'bloc/home_bloc.dart';
  
95edef4f   liangchengyou   feat:更新适配代码
14
  class HomePage extends StatelessWidget {
8988aa69   liangchengyou   feat:首页+课程列表数据获取
15
16
17
18
    const HomePage({super.key, this.moduleId});
  
    /// 模块id
    final String? moduleId;
95edef4f   liangchengyou   feat:更新适配代码
19
20
21
  
    @override
    Widget build(BuildContext context) {
60e47f7c   liangchengyou   feat:课程选择功能
22
      return BlocProvider(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
23
        create: (context) => HomeBloc(moduleId)..add(RequestDataEvent()),
60e47f7c   liangchengyou   feat:课程选择功能
24
25
26
27
28
29
30
31
        child: _HomePageView(),
      );
    }
  }
  
  class _HomePageView extends StatelessWidget {
    void _headerActionEvent(HeaderActionType type) {
      if (type == HeaderActionType.video) {
08a0f5a8   liangchengyou   feat:路由方式更新
32
        pushNamed(AppRouteName.reAfter);
60e47f7c   liangchengyou   feat:课程选择功能
33
      } else if (type == HeaderActionType.phase) {
08a0f5a8   liangchengyou   feat:路由方式更新
34
        pushNamed(AppRouteName.lesson);
60e47f7c   liangchengyou   feat:课程选择功能
35
      } else if (type == HeaderActionType.listen) {
08a0f5a8   liangchengyou   feat:路由方式更新
36
        pushNamed(AppRouteName.listen);
d35a4e87   liangchengyou   feat:磨耳朵功能UI
37
      } else if (type == HeaderActionType.shop) {
08a0f5a8   liangchengyou   feat:路由方式更新
38
        pushNamed(AppRouteName.shop);
056970d8   Key   feat: api
39
      } else if (type == HeaderActionType.user) {
08a0f5a8   liangchengyou   feat:路由方式更新
40
        pushNamed(AppRouteName.user);
60e47f7c   liangchengyou   feat:课程选择功能
41
      } else {
608c05b4   liangchengyou   feat:兑换课程
42
  
60e47f7c   liangchengyou   feat:课程选择功能
43
44
45
46
47
      }
    }
  
    @override
    Widget build(BuildContext context) {
3c1d5c64   liangchengyou   feat:练习功能完成
48
      final bloc = BlocProvider.of<HomeBloc>(context);
c61b3c1a   Key   feat: toast_util....
49
      return BlocListener<HomeBloc, HomeState>(
3c1d5c64   liangchengyou   feat:练习功能完成
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        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';
            }
            debugPrint(videoUrl);
            if (videoUrl.isEmpty) {
              return;
            }
08a0f5a8   liangchengyou   feat:路由方式更新
69
            pushNamed(AppRouteName.lookVideo,arguments: {'videoUrl':videoUrl,'title':title});
3c1d5c64   liangchengyou   feat:练习功能完成
70
71
          }
        },
d35a4e87   liangchengyou   feat:磨耳朵功能UI
72
        child: _homeView(),
95edef4f   liangchengyou   feat:更新适配代码
73
74
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
75
  
c61b3c1a   Key   feat: toast_util....
76
    Widget _homeView() => BlocBuilder<HomeBloc, HomeState>(builder: (context, state) {
08a0f5a8   liangchengyou   feat:路由方式更新
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
      final bloc = BlocProvider.of<HomeBloc>(context);
      return Scaffold(
        body: Container(
          color: Colors.white,
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                HomeTabHeaderWidget(
                  actionTap: (HeaderActionType type) {
                    _headerActionEvent(type);
                  },
                ),
                Expanded(
                    child: ListView.builder(
                        itemCount: bloc.modelData?.totalCourseLesson,
                        scrollDirection: Axis.horizontal,
                        itemBuilder: (BuildContext context, int index) {
                          CourseCourseLessons? data = bloc.modelData?.courseLessons?[index];
                          if (data?.courseType == 5) {
                            //彩蛋
                            return GestureDetector(
                              onTap: () {
                                if (data!.lock!) {
                                  showToast('当前课程暂未解锁');
                                  return;
                                }
                                bloc.add(RequestVideoLessonEvent(data.id!,data.courseType!));
                              },
                              child: HomeBoundsItem(
                                imageUrl: data?.coverUrl,
                              ),
                            );
                          } else {
                            return GestureDetector(
                              onTap: () {
                                debugPrint('>>>>>>>类型${data?.courseType}');
                                if (data!.lock!) {
                                  showToast('当前课程暂未解锁');
                                  return;
                                }
                                if (data.courseType == 4) {//绘本
                                  return;
                                }
608c05b4   liangchengyou   feat:兑换课程
121
  
08a0f5a8   liangchengyou   feat:路由方式更新
122
123
124
125
                                if (data.courseType == 3) {//练习
                                  Navigator.of(context).pushNamed(AppRouteName.topicPic,arguments: {'courseLessonId':data.id!});
                                  return;
                                }
3c1d5c64   liangchengyou   feat:练习功能完成
126
  
08a0f5a8   liangchengyou   feat:路由方式更新
127
128
129
130
131
                                //儿歌/看视频
                                bloc.add(RequestVideoLessonEvent(data.id!,data.courseType!));
                              },
                              child: HomeVideoItem(
                                lessons: data,
d35a4e87   liangchengyou   feat:磨耳朵功能UI
132
                              ),
08a0f5a8   liangchengyou   feat:路由方式更新
133
134
135
136
137
138
139
140
141
142
143
144
                            );
                          }
                        })),
                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
145
                        ),
08a0f5a8   liangchengyou   feat:路由方式更新
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
                        Container(
                          decoration: BoxDecoration(
                            color: Colors.blue,
                            borderRadius: BorderRadius.circular(14.5.r),
                          ),
                          padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 24.w),
                          child: Text(
                            '${(bloc.modelData?.nowCourseLesson)}/${bloc.modelData?.totalCourseLesson}',
                            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
168
            ),
08a0f5a8   liangchengyou   feat:路由方式更新
169
170
171
172
          ),
        ),
      );
    });
056970d8   Key   feat: api
173
  }