Skip to content

Commit ddda9f7

Browse files
committed
feat(home): 完成首页
1 parent 68a83a9 commit ddda9f7

File tree

16 files changed

+521
-14
lines changed

16 files changed

+521
-14
lines changed

.vscode/launch.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// 使用 IntelliSense 了解相关属性。
3+
// 悬停以查看现有属性的描述。
4+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "luckincoffee",
9+
"request": "launch",
10+
"type": "dart"
11+
}
12+
]
13+
}

lib/assets/images/home/footer-img.png

76.9 KB
Loading

lib/main.dart

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
// @dart=2.9
12
import 'package:flutter/material.dart';
23
import 'package:luckincoffee/pages/main/main.dart';
34
import 'package:luckincoffee/routes/router.dart';
5+
import 'package:luckincoffee/shared/size-hot.dart';
6+
import 'package:luckincoffee/shared/theme.dart';
47

5-
void main() => runApp(MaterialApp(
8+
void main() {
9+
SizeHot.initialize();
10+
11+
runApp(App());
12+
}
13+
14+
class App extends StatelessWidget {
15+
@override
16+
Widget build(BuildContext context) {
17+
return MaterialApp(
18+
theme: AppTheme.appThtme,
619
routes: AppRoutes.routes,
720
initialRoute: AppRoutes.initialRoute,
8-
));
21+
// home: Scaffold(
22+
// body: Center(
23+
// child: Builder(
24+
// builder: (context) {
25+
// return Container(
26+
// color: Theme.of(context).primaryColor,
27+
// );
28+
// },
29+
// ),
30+
// ),
31+
// ),
32+
);
33+
}
34+
}

lib/pages/cart/cart.dart

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'package:flutter/material.dart';
2+
3+
class CartPage extends StatelessWidget {
4+
static const String routerName = '/cart';
5+
6+
@override
7+
Widget build(BuildContext context) {
8+
return Scaffold(
9+
appBar: AppBar(
10+
title: Text('购物车'),
11+
),
12+
body: Center(
13+
child: Text('购物车'),
14+
),
15+
floatingActionButton: FloatingActionButton(
16+
onPressed: () {
17+
print('购物车');
18+
},
19+
child: Icon(Icons.add),
20+
),
21+
);
22+
}
23+
}

lib/pages/home/home-content.dart

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:luckincoffee/extensions/int-extensions.dart';
3+
import 'package:luckincoffee/utils/icon.dart';
4+
5+
import 'home-swiper.dart';
6+
7+
final List<SelectItemViewModel> selects = [
8+
SelectItemViewModel(
9+
title: '立即下单',
10+
subtitle: 'ORDER NOW',
11+
iconData: IconFonts.icontupian3,
12+
),
13+
SelectItemViewModel(
14+
title: '咖啡钱包',
15+
subtitle: 'COFFEE WALLET',
16+
iconData: IconFonts.icontupian,
17+
),
18+
SelectItemViewModel(
19+
title: '送Ta咖啡',
20+
subtitle: 'SEND COFFEE',
21+
iconData: IconFonts.icontupian1,
22+
),
23+
SelectItemViewModel(
24+
title: '企业账户',
25+
subtitle: 'ENTERPRISE ACCOUNT',
26+
iconData: IconFonts.icontupian7,
27+
),
28+
];
29+
30+
class HomeContent extends StatefulWidget {
31+
@override
32+
_HomeContentState createState() => _HomeContentState();
33+
}
34+
35+
class _HomeContentState extends State<HomeContent> {
36+
/// 购买类型
37+
/// 1:自提
38+
/// 2:外送
39+
int type = 0;
40+
41+
@override
42+
Widget build(BuildContext context) {
43+
return Column(children: [
44+
HomeSwiper(),
45+
Container(
46+
padding: EdgeInsets.symmetric(horizontal: 20.px),
47+
child: Column(
48+
mainAxisSize: MainAxisSize.min,
49+
children: [
50+
ListTile(
51+
contentPadding: EdgeInsets.zero,
52+
title: Text('青年汇店'),
53+
subtitle: Text('距你53m'),
54+
trailing: buildTrailing(context),
55+
),
56+
buildSelects(),
57+
buildFooterImg(),
58+
],
59+
)),
60+
]);
61+
}
62+
63+
/// 渲染右侧购买类型
64+
Widget buildTrailing(BuildContext context) {
65+
/// 修改购买类型
66+
void handleTypeChange() {
67+
setState(() {
68+
type = type == 0 ? 1 : 0;
69+
});
70+
}
71+
72+
return Container(
73+
width: 90.px,
74+
height: 36.px,
75+
padding: EdgeInsets.all(2.px),
76+
decoration: BoxDecoration(
77+
border: Border.all(
78+
color: Theme.of(context).primaryColor,
79+
width: 1.0,
80+
),
81+
borderRadius: BorderRadius.circular(100.px),
82+
),
83+
child: Row(
84+
mainAxisSize: MainAxisSize.max,
85+
mainAxisAlignment: MainAxisAlignment.spaceAround,
86+
children: [
87+
buildTrailingItem(context: context, title: '自提', isActive: type == 0, onTap: handleTypeChange),
88+
buildTrailingItem(context: context, title: '外送', isActive: type == 1, onTap: handleTypeChange),
89+
],
90+
),
91+
);
92+
}
93+
94+
/// 渲染购买类型
95+
Widget buildTrailingItem({required BuildContext context, required String title, required bool isActive, required Function onTap}) {
96+
return Expanded(
97+
child: GestureDetector(
98+
onTap: () {
99+
onTap();
100+
},
101+
child: Container(
102+
height: double.infinity,
103+
decoration: BoxDecoration(borderRadius: BorderRadius.circular(100.px), color: isActive ? Theme.of(context).primaryColor : Colors.transparent),
104+
alignment: Alignment(0, 0),
105+
child: Text(title, style: Theme.of(context).textTheme.headline1?.copyWith(color: isActive ? Colors.white : Colors.black87)),
106+
),
107+
),
108+
);
109+
}
110+
111+
Widget buildSelects() {
112+
return Container(
113+
child: ListView.separated(
114+
padding: EdgeInsets.zero,
115+
shrinkWrap: true,
116+
physics: ScrollPhysics(),
117+
itemCount: selects.length,
118+
itemBuilder: (ctx, index) {
119+
return buildSelectsItem(title: selects[index].title, subtitle: selects[index].subtitle, iconData: selects[index].iconData);
120+
},
121+
separatorBuilder: (ctx, index) => Divider(),
122+
),
123+
);
124+
}
125+
126+
/// 渲染底部选择菜单
127+
Widget buildSelectsItem({
128+
required String title,
129+
required String subtitle,
130+
required IconData iconData,
131+
}) {
132+
return ListTile(
133+
contentPadding: EdgeInsets.zero,
134+
title: Text(
135+
title,
136+
style: TextStyle(fontWeight: FontWeight.bold),
137+
),
138+
subtitle: Text(
139+
subtitle,
140+
),
141+
trailing: CircleAvatar(
142+
backgroundColor: Colors.transparent,
143+
child: Container(
144+
width: double.infinity,
145+
height: double.infinity,
146+
decoration: BoxDecoration(border: Border.all(), borderRadius: BorderRadius.circular(100)),
147+
child: Icon(
148+
iconData,
149+
color: Color(0xff64443c),
150+
))),
151+
);
152+
}
153+
154+
/// 渲染底部图片
155+
Image buildFooterImg() {
156+
return Image.asset(
157+
'lib/assets/images/home/footer-img.png',
158+
fit: BoxFit.cover,
159+
);
160+
}
161+
}
162+
163+
/// 菜单 item 数据模型
164+
class SelectItemViewModel {
165+
late final String title;
166+
late final String subtitle;
167+
late final IconData iconData;
168+
169+
SelectItemViewModel({required this.title, required this.subtitle, required this.iconData});
170+
}

lib/pages/home/home-swiper.dart

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import 'package:flutter_swiper/flutter_swiper.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:luckincoffee/extensions/int-extensions.dart';
4+
import 'package:luckincoffee/utils/icon.dart';
5+
6+
final List<Image> banners = [
7+
Image.asset(
8+
'lib/assets/images/home/banner-1.jpg',
9+
fit: BoxFit.cover,
10+
),
11+
Image.asset(
12+
'lib/assets/images/home/banner-2.jpg',
13+
fit: BoxFit.cover,
14+
),
15+
Image.asset(
16+
'lib/assets/images/home/banner-3.jpg',
17+
fit: BoxFit.cover,
18+
),
19+
];
20+
21+
class HomeSwiper extends StatefulWidget {
22+
@override
23+
_HomeSwiperState createState() => _HomeSwiperState();
24+
}
25+
26+
class _HomeSwiperState extends State<HomeSwiper> {
27+
@override
28+
Widget build(BuildContext context) {
29+
return Container(
30+
height: 208.px,
31+
child: Stack(
32+
children: [
33+
Swiper(
34+
index: 0,
35+
itemCount: banners.length,
36+
itemBuilder: (ctx, index) => banners[index],
37+
pagination: SwiperPagination(builder: DotSwiperPaginationBuilder(size: 8, activeSize: 8)),
38+
autoplay: true,
39+
duration: 500,
40+
autoplayDelay: 5000,
41+
),
42+
Positioned(
43+
child: CircleAvatar(
44+
backgroundColor: Colors.black26,
45+
child: Icon(
46+
IconFonts.icontupian4,
47+
color: Colors.white,
48+
size: 20,
49+
)),
50+
right: 20,
51+
top: 60,
52+
)
53+
],
54+
),
55+
);
56+
}
57+
}

lib/pages/home/home.dart

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:luckincoffee/pages/home/home-content.dart';
3+
import 'package:luckincoffee/pages/home/home-swiper.dart';
4+
5+
class HomePage extends StatelessWidget {
6+
static const String routerName = '/home';
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
return Scaffold(
11+
body: HomeContent(),
12+
);
13+
}
14+
}

lib/pages/main/initialize.dart

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
4+
import 'package:luckincoffee/pages/home/home.dart';
5+
import 'package:luckincoffee/pages/menu/menu.dart';
6+
import 'package:luckincoffee/pages/orders/orders.dart';
7+
import 'package:luckincoffee/pages/cart/cart.dart';
8+
import 'package:luckincoffee/pages/profile/profile.dart';
9+
10+
import 'package:luckincoffee/utils/icon.dart';
11+
12+
final List<BottomNavigationBarItem> tabbar = [
13+
BottomNavigationBarItem(
14+
icon: Icon(IconFonts.iconlogo_not_text),
15+
label: '首页',
16+
),
17+
BottomNavigationBarItem(
18+
icon: Icon(IconFonts.iconcaidan),
19+
label: '菜单',
20+
),
21+
BottomNavigationBarItem(
22+
icon: Icon(IconFonts.iconorder),
23+
label: '订单',
24+
),
25+
BottomNavigationBarItem(
26+
icon: Icon(IconFonts.icongouwuche),
27+
label: '购物车',
28+
),
29+
BottomNavigationBarItem(
30+
icon: Icon(IconFonts.iconmine),
31+
label: '我的',
32+
),
33+
];
34+
35+
final List<Widget> pages = [
36+
HomePage(),
37+
MenuPage(),
38+
OrdersPage(),
39+
CartPage(),
40+
ProfilePage(),
41+
];

0 commit comments

Comments
 (0)