Blame view

lib/pages/home/home_page.dart 5.91 KB
95edef4f   liangchengyou   feat:更新适配代码
1
  import 'package:flutter/material.dart';
60e47f7c   liangchengyou   feat:课程选择功能
2
  import 'package:flutter_bloc/flutter_bloc.dart';
6f617434   liangchengyou   feat:磨耳朵/视频跟读列表页接口调整
3
  import 'package:flutter_easyloading/flutter_easyloading.dart';
d35a4e87   liangchengyou   feat:磨耳朵功能UI
4
5
  import 'package:flutter_screenutil/flutter_screenutil.dart';
  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';
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) {
9d080046   liangchengyou   feat:视频跟读逻辑
32
        Navigator.of(AppRouter.context).pushNamed(AppRouteName.reAfter);
60e47f7c   liangchengyou   feat:课程选择功能
33
34
35
      } else if (type == HeaderActionType.phase) {
        Navigator.of(AppRouter.context).pushNamed(AppRouteName.lesson);
      } else if (type == HeaderActionType.listen) {
d35a4e87   liangchengyou   feat:磨耳朵功能UI
36
37
        Navigator.of(AppRouter.context).pushNamed(AppRouteName.listen);
      } else if (type == HeaderActionType.shop) {
d1d32220   liangchengyou   feat:兑换课程+购买记录
38
        Navigator.of(AppRouter.context).pushNamed(AppRouteName.shop);
056970d8   Key   feat: api
39
      } else if (type == HeaderActionType.user) {
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
40
41
        Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic);
        // Navigator.of(AppRouter.context).pushNamed(AppRouteName.user);
60e47f7c   liangchengyou   feat:课程选择功能
42
      } else {
624214d0   liangchengyou   feat:看题选字/选图UI和部分逻辑
43
        // Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic);
119ba920   liangchengyou   feat:视频播放器
44
        // Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicWord);
95e3448c   liangchengyou   feat:听音选图/选字
45
46
        // Navigator.of(AppRouter.context).pushNamed(AppRouteName.lookVideo);
        // Navigator.of(AppRouter.context).pushNamed(AppRouteName.voicePic);
725dc3f2   liangchengyou   feat:语音问答界面UI
47
48
        // Navigator.of(AppRouter.context).pushNamed(AppRouteName.voiceWord);
        Navigator.of(AppRouter.context).pushNamed(AppRouteName.voiceAnswer);
60e47f7c   liangchengyou   feat:课程选择功能
49
50
51
52
53
54
55
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return BlocListener<HomeBloc,HomeState>(
        listener: (context, state){},
d35a4e87   liangchengyou   feat:磨耳朵功能UI
56
        child: _homeView(),
95edef4f   liangchengyou   feat:更新适配代码
57
58
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  
    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(
                      actionTap: (HeaderActionType type) {
                        _headerActionEvent(type);
                      },
                    ),
                    Expanded(
65e33ae8   liangchengyou   feat:更新代码
76
                      child: ListView.builder(
ad8454ca   liangchengyou   feat:调整模型
77
                          itemCount: bloc.modelData?.totalCourseLesson,
65e33ae8   liangchengyou   feat:更新代码
78
79
                          scrollDirection: Axis.horizontal,
                          itemBuilder: (BuildContext context, int index){
8988aa69   liangchengyou   feat:首页+课程列表数据获取
80
81
                            CourseCourseLessons? data = bloc.modelData?.courseLessons?[index];
                            if (data?.courseType == 5) {//彩蛋
6f617434   liangchengyou   feat:磨耳朵/视频跟读列表页接口调整
82
83
84
85
86
87
88
89
90
91
                              return GestureDetector(
                                onTap: (){
                                  if (data!.lock!) {
                                    return;
                                  }
                                  EasyLoading.showToast('点击事件');
                                },
                                child: HomeBoundsItem(
                                  imageUrl: data?.coverUrl,
                                ),
8988aa69   liangchengyou   feat:首页+课程列表数据获取
92
93
                              );
                            } else {
6f617434   liangchengyou   feat:磨耳朵/视频跟读列表页接口调整
94
95
96
97
98
99
100
101
102
103
                              return GestureDetector(
                                onTap: () {
                                  if (data!.lock!) {
                                    return;
                                  }
                                  EasyLoading.showToast('点击事件');
                                },
                                child: HomeVideoItem(
                                  lessons: data,
                                ),
8988aa69   liangchengyou   feat:首页+课程列表数据获取
104
105
                              );
                            }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
106
                          })
d35a4e87   liangchengyou   feat:磨耳朵功能UI
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
                    ),
                    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: Colors.blue,
                                borderRadius: BorderRadius.circular(14.5.r),
                              ),
                              padding: EdgeInsets.symmetric(vertical: 8.h,horizontal: 24.w),
                              child: Text(
8988aa69   liangchengyou   feat:首页+课程列表数据获取
125
                                '${(bloc.modelData?.nowCourseLesson)}/${bloc.modelData?.totalCourseLesson}',
d35a4e87   liangchengyou   feat:磨耳朵功能UI
126
127
128
129
130
131
132
133
134
135
                                style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 12.sp
                                ),
                              ),
                            ),
                            Image.asset(
                              'blue-positive'.assetPng,
                              height: 47.h,
                              width: 80.w,
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
136
                              // color: Colors.red,
d35a4e87   liangchengyou   feat:磨耳朵功能UI
137
138
139
140
141
142
143
144
145
146
147
                            ),
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ),
          );
        });
056970d8   Key   feat: api
148
  }