60e47f7c
liangchengyou
feat:课程选择功能
|
1
2
3
4
5
6
|
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wow_english/common/extension/string_extension.dart';
import 'package:wow_english/common/widgets/we_app_bar.dart';
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
7
8
|
import 'package:wow_english/models/course_module_entity.dart';
import 'package:wow_english/route/route.dart';
|
4b358e22
liangchengyou
feat:调整文件结构
|
9
10
11
|
import 'bloc/lesson_bloc.dart';
import 'widgets/lesson_item_widget.dart';
|
60e47f7c
liangchengyou
feat:课程选择功能
|
12
13
14
15
16
17
|
class LessonPage extends StatelessWidget {
const LessonPage({super.key, this.starPageIndex});
final int? starPageIndex;
|
60e47f7c
liangchengyou
feat:课程选择功能
|
18
19
20
21
22
23
24
25
|
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => LessonBloc(
starPageIndex??0,
PageController(
initialPage: starPageIndex??0,
viewportFraction: 0.3
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
26
27
|
),
)..requestData(),
|
60e47f7c
liangchengyou
feat:课程选择功能
|
28
29
30
31
32
33
34
|
child: _LessonPageView(),
);
}
}
class _LessonPageView extends StatelessWidget {
|
f0d56772
liangchengyou
feat:更新尺寸适配
|
35
|
final double _cardHeight = 240.h;
|
60e47f7c
liangchengyou
feat:课程选择功能
|
36
|
|
60e47f7c
liangchengyou
feat:课程选择功能
|
37
38
39
40
41
42
43
44
|
final double _scale = 0.8;
@override
Widget build(BuildContext context) {
return BlocListener<LessonBloc,LessonState>(
listener: (context, state){},
child: Scaffold(
appBar: WEAppBar(
|
d35a4e87
liangchengyou
feat:磨耳朵功能UI
|
45
46
47
48
49
50
51
52
53
54
|
leading: IconButton(
onPressed: (){
Navigator.pop(context);
},
icon: Image.asset(
'back'.assetPng,
height: 43,
width: 43,
)
),
|
60e47f7c
liangchengyou
feat:课程选择功能
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
actions: <Widget>[
IconButton(
icon: Image.asset('shop'.assetPng),
color: Colors.white,
onPressed: () {
EasyLoading.showToast('购买');
},
)
],
),
body: _lessViewWidget(),
),
);
}
Widget _lessViewWidget() => BlocBuilder<LessonBloc,LessonState>(
builder: (context, state){
final bloc = BlocProvider.of<LessonBloc>(context);
return Center(
child: SafeArea(
child: Column(
children: [
SizedBox(
height: _cardHeight,
child: PageView.builder(
|
993c1a04
liangchengyou
feat:添加数据模型
|
80
|
itemCount: bloc.listData.length,
|
60e47f7c
liangchengyou
feat:课程选择功能
|
81
82
83
84
85
86
87
88
89
|
controller: bloc.pageController,
onPageChanged: (int index) {
bloc.add(PageViewChangeIndexEvent(index));
},
itemBuilder: (context,index) => _itemTransCard(index)
),
),
32.verticalSpace,
SizedBox(
|
f0d56772
liangchengyou
feat:更新尺寸适配
|
90
|
height: 32.h,
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
91
|
width: double.infinity,
|
60e47f7c
liangchengyou
feat:课程选择功能
|
92
|
child: ListView.builder(
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
93
|
itemCount: bloc.listData.length,
|
60e47f7c
liangchengyou
feat:课程选择功能
|
94
95
96
|
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context,int index){
return Container(
|
f0d56772
liangchengyou
feat:更新尺寸适配
|
97
98
|
height: 32.h,
width: 66.w,
|
60e47f7c
liangchengyou
feat:课程选择功能
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
padding: const EdgeInsets.symmetric(horizontal: 5),
child: GestureDetector(
onTap: () {
if (index == bloc.currentPageIndex) {
return;
}
int mill = (index - bloc.currentPageIndex) > 0 ? 100 * (index - bloc.currentPageIndex):100 * (bloc.currentPageIndex-index);
bloc.pageController.animateToPage(index, duration: Duration(milliseconds: mill), curve: Curves.ease);
},
child: Container(
height: bloc.currentPageIndex == index ? 32:20,
decoration: BoxDecoration(
color: bloc.currentPageIndex == index ? Colors.red:Colors.white,
border: Border.all(
width: 0.5,
color: Colors.black,
),
),
alignment: Alignment.center,
child: Text(
(index+1).toString(),
style: TextStyle(
color: bloc.currentPageIndex == index ? Colors.white:Colors.black
),
),
),
),
);
}),
|
60e47f7c
liangchengyou
feat:课程选择功能
|
128
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
155
156
157
158
159
160
161
162
163
164
|
)
],
),
),
);
});
Widget _itemTransCard(int index) => BlocBuilder<LessonBloc,LessonState>(
builder: (context, state) {
final bloc = BlocProvider.of<LessonBloc>(context);
Matrix4 matrix4 = Matrix4.identity();
if (index == bloc.currentPageIndex.floor()) {
//当前的item
double currScale = (1 - (bloc.currentPageIndex - index) * (1 - _scale)).toDouble();
var currTrans = _cardHeight * (1 - currScale) / 2;
matrix4 = Matrix4.diagonal3Values(1.0, currScale, 1.0)
..setTranslationRaw(0.0, currTrans, 0.0);
} else if (index == bloc.currentPageIndex.floor() + 1) {
//右边的item
var currScale = _scale + (bloc.currentPageIndex - index + 1) * (1 - _scale);
var currTrans = _cardHeight * (1 - currScale) / 2;
matrix4 = Matrix4.diagonal3Values(1.0, currScale, 1.0)
..setTranslationRaw(0.0, currTrans, 0.0);
} else if (index == bloc.currentPageIndex - 1) {
//左边
var currScale = (1 - (bloc.currentPageIndex - index) * (1 - _scale)).toDouble();
var currTrans = _cardHeight * (1 - currScale) / 2;
matrix4 = Matrix4.diagonal3Values(1.0, currScale, 1.0)
..setTranslationRaw(0.0, currTrans, 0.0);
} else {
//其他,不在屏幕显示的item
matrix4 = Matrix4.diagonal3Values(1.0, _scale, 1.0)
..setTranslationRaw(0.0, _cardHeight * (1 - _scale) / 2, 0.0);
}
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
165
|
CourseModuleEntity? model = bloc.listData[index];
|
60e47f7c
liangchengyou
feat:课程选择功能
|
166
167
168
169
|
return Transform(
transform: matrix4,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
170
171
172
173
174
175
176
|
child: LessonItemWidget(
model: model,
isSelected: bloc.currentPageIndex == index,
onClickEvent: () {
Navigator.of(context).pushNamedAndRemoveUntil(AppRouteName.home, (route) => false,arguments: {'moduleId':model?.id});
},
),
|
60e47f7c
liangchengyou
feat:课程选择功能
|
177
178
179
|
),
);
});
|
60e47f7c
liangchengyou
feat:课程选择功能
|
180
|
}
|