Blame view

lib/pages/home/home_page.dart 5.7 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) {
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) {
49e626e9   Key   feat: log_util.dart
40
        Navigator.of(AppRouter.context).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) {
c61b3c1a   Key   feat: toast_util....
48
49
      return BlocListener<HomeBloc, HomeState>(
        listener: (context, state) {},
d35a4e87   liangchengyou   feat:磨耳朵功能UI
50
        child: _homeView(),
95edef4f   liangchengyou   feat:更新适配代码
51
52
      );
    }
d35a4e87   liangchengyou   feat:磨耳朵功能UI
53
  
c61b3c1a   Key   feat: toast_util....
54
    Widget _homeView() => BlocBuilder<HomeBloc, HomeState>(builder: (context, state) {
d35a4e87   liangchengyou   feat:磨耳朵功能UI
55
56
57
58
          final bloc = BlocProvider.of<HomeBloc>(context);
          return Scaffold(
            body: Container(
              color: Colors.white,
c61b3c1a   Key   feat: toast_util....
59
              child: Center(
d35a4e87   liangchengyou   feat:磨耳朵功能UI
60
61
62
63
64
65
66
67
68
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    HomeTabHeaderWidget(
                      actionTap: (HeaderActionType type) {
                        _headerActionEvent(type);
                      },
                    ),
                    Expanded(
c61b3c1a   Key   feat: toast_util....
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
                        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!) {
                                      return;
                                    }
                                    showToast('点击事件');
                                  },
                                  child: HomeBoundsItem(
                                    imageUrl: data?.coverUrl,
                                  ),
                                );
                              } else {
                                return GestureDetector(
                                  onTap: () {
                                    if (data!.lock!) {
                                      return;
                                    }
608c05b4   liangchengyou   feat:兑换课程
93
94
95
96
97
98
99
100
                                    if (data!.courseType == 4) {//绘本
                                      return;
                                    }
  
                                    if (data.courseType == 3) {//练习
                                      Navigator.of(context).pushNamed(AppRouteName.topicPic,arguments: {'courseLessonId':data!.id});
                                      return;
                                    }
c61b3c1a   Key   feat: toast_util....
101
102
103
104
105
106
107
                                  },
                                  child: HomeVideoItem(
                                    lessons: data,
                                  ),
                                );
                              }
                            })),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
                    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),
                              ),
c61b3c1a   Key   feat: toast_util....
123
                              padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 24.w),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
124
                              child: Text(
8988aa69   liangchengyou   feat:首页+课程列表数据获取
125
                                '${(bloc.modelData?.nowCourseLesson)}/${bloc.modelData?.totalCourseLesson}',
c61b3c1a   Key   feat: toast_util....
126
                                style: TextStyle(color: Colors.white, fontSize: 12.sp),
d35a4e87   liangchengyou   feat:磨耳朵功能UI
127
128
129
130
131
132
                              ),
                            ),
                            Image.asset(
                              'blue-positive'.assetPng,
                              height: 47.h,
                              width: 80.w,
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
133
                              // color: Colors.red,
d35a4e87   liangchengyou   feat:磨耳朵功能UI
134
135
136
137
138
139
140
141
142
143
144
                            ),
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ),
          );
        });
056970d8   Key   feat: api
145
  }