|
@@ -1,3 +1,4 @@
|
|
1
|
+import 'package:flutter/cupertino.dart';
|
1
|
2
|
import 'package:flutter/material.dart';
|
2
|
3
|
import 'package:get/get.dart';
|
3
|
4
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
@@ -8,16 +9,56 @@ class Home extends StatefulWidget {
|
8
|
9
|
@override
|
9
|
10
|
_Home createState() => _Home();
|
10
|
11
|
}
|
11
|
|
-class _Home extends State<Home> {
|
12
|
12
|
|
|
13
|
+class _Home extends State<Home> {
|
13
|
14
|
List images = [
|
14
|
15
|
['images/index/index.png', 'images/index/indexActive.png'],
|
15
|
16
|
['images/index/job.png', 'images/index/jobActive.png'],
|
16
|
17
|
['images/index/user.png', 'images/index/userActive.png'],
|
17
|
18
|
];
|
18
|
19
|
|
19
|
|
- final List _titles = ['首页', '好物', '双11'];
|
|
20
|
+ final List _titles = ['首页', '订单列表', '个人中心'];
|
20
|
21
|
int _currentIndex = 0;
|
|
22
|
+ final tabTextStyleSelected =
|
|
23
|
+ TextStyle(color: const Color(0xFF06B03B),fontSize: 15.sp,fontWeight: FontWeight.bold); //选线卡选中字体颜色
|
|
24
|
+ final tabTextStyleNormal =
|
|
25
|
+ TextStyle(color: const Color(0xFF323232),fontSize: 15.sp,fontWeight: FontWeight.bold); //选项卡未选中字体颜色
|
|
26
|
+ int _tabIndex = 0; //选项卡下标
|
|
27
|
+
|
|
28
|
+ var _body = [Text('我是首页'), Text('我是订单列表'), Text('我是个人中心')];
|
|
29
|
+ TextStyle getTabTextStyle(int curIndex) {
|
|
30
|
+ //设置tabbar 选中和未选中的状态文本
|
|
31
|
+ if (curIndex == _tabIndex) {
|
|
32
|
+ return tabTextStyleSelected;
|
|
33
|
+ }
|
|
34
|
+ return tabTextStyleNormal;
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ Image getTabIcon(int curIndex) {
|
|
38
|
+ //设置tabbar选中和未选中的状态图标
|
|
39
|
+ if (curIndex == _tabIndex) {
|
|
40
|
+ return Image.asset(
|
|
41
|
+ images[curIndex][1],
|
|
42
|
+ width: 20.w,
|
|
43
|
+ height: 20.w,
|
|
44
|
+ );
|
|
45
|
+ }
|
|
46
|
+ return Image.asset(
|
|
47
|
+ images[curIndex][0],
|
|
48
|
+ width: 20.w,
|
|
49
|
+ height: 20.w,
|
|
50
|
+ );
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ Image getTabImage(path) {
|
|
54
|
+ return Image.asset(path, width: 26.w, height: 26.w);
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ // 切换底部选项卡,标题的变化设置
|
|
58
|
+ Text getTabTitle(int curIndex) {
|
|
59
|
+ return Text(_titles[curIndex], style: getTabTextStyle(curIndex));
|
|
60
|
+ }
|
|
61
|
+
|
21
|
62
|
@override
|
22
|
63
|
Widget build(BuildContext context) {
|
23
|
64
|
return Scaffold(
|
|
@@ -27,53 +68,42 @@ class _Home extends State<Home> {
|
27
|
68
|
backgroundColor: Colors.white,
|
28
|
69
|
title: Text(
|
29
|
70
|
'首页',
|
30
|
|
- style:
|
31
|
|
- TextStyle(color: Colors.black, fontSize: 17.sp, letterSpacing: 2),
|
|
71
|
+ style: TextStyle(
|
|
72
|
+ color: Colors.black,
|
|
73
|
+ fontSize: 17.sp,
|
|
74
|
+ letterSpacing: 2,
|
|
75
|
+ fontWeight: FontWeight.bold
|
|
76
|
+ ),
|
32
|
77
|
),
|
33
|
78
|
),
|
|
79
|
+ body: _body[_tabIndex],
|
|
80
|
+ bottomNavigationBar: Container(
|
|
81
|
+ height: 65.h,
|
34
|
82
|
|
|
83
|
+ child: Row(
|
|
84
|
+ mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
85
|
+ children: [
|
|
86
|
+ Column(
|
|
87
|
+ children: [
|
|
88
|
+ getTabIcon(0),
|
|
89
|
+ getTabTitle(0)
|
|
90
|
+ ],
|
|
91
|
+ ),
|
|
92
|
+ Column(
|
|
93
|
+ children: [
|
|
94
|
+ getTabIcon(1),
|
|
95
|
+ getTabTitle(1)
|
|
96
|
+ ],
|
|
97
|
+ ),
|
|
98
|
+ Column(
|
|
99
|
+ children: [
|
|
100
|
+ getTabIcon(2),
|
|
101
|
+ getTabTitle(2)
|
|
102
|
+ ],
|
|
103
|
+ ),
|
|
104
|
+ ],
|
|
105
|
+ ),
|
|
106
|
+ ),
|
35
|
107
|
);
|
36
|
108
|
}
|
37
|
|
- }
|
38
|
|
-// class Home extends StatelessWidget {
|
39
|
|
-// @override
|
40
|
|
-// Widget build(BuildContext context) {
|
41
|
|
-// // controller.person
|
42
|
|
-// return Scaffold(
|
43
|
|
-// appBar: AppBar(
|
44
|
|
-// elevation: 0,
|
45
|
|
-// centerTitle: true,
|
46
|
|
-// backgroundColor: Colors.white,
|
47
|
|
-// title: Text(
|
48
|
|
-// '首页',
|
49
|
|
-// style:
|
50
|
|
-// TextStyle(color: Colors.black, fontSize: 17.sp, letterSpacing: 2),
|
51
|
|
-// ),
|
52
|
|
-// ),
|
53
|
|
-// body: GestureDetector(
|
54
|
|
-// onTap: () {
|
55
|
|
-// Get.snackbar(
|
56
|
|
-// "Hey i'm a Get SnackBar!", // title
|
57
|
|
-// "It's unbelievable! I'm using SnackBar without context, without boilerplate, without Scaffold, it is something truly amazing!", // message
|
58
|
|
-// icon: Icon(Icons.alarm),
|
59
|
|
-// shouldIconPulse: true,
|
60
|
|
-// barBlur: 20,
|
61
|
|
-// isDismissible: true,
|
62
|
|
-// duration: Duration(seconds: 3),
|
63
|
|
-// );
|
64
|
|
-// // Get.snackbar('Hi', 'i am a modern snackbar');
|
65
|
|
-// },
|
66
|
|
-// child: const Text("首页内容"),
|
67
|
|
-// ),
|
68
|
|
-// bottomNavigationBar: BottomNavigationBar(
|
69
|
|
-// items: const <BottomNavigationBarItem>[
|
70
|
|
-// BottomNavigationBarItem(title: Text('首页'),icon: Icon(Icons.home)),
|
71
|
|
-// BottomNavigationBarItem(title: Text('书籍'),icon: Icon(Icons.book)),
|
72
|
|
-// BottomNavigationBarItem(title: Text('我的'),icon: Icon(Icons.perm_identity)),
|
73
|
|
-// ],
|
74
|
|
-// ),
|
75
|
|
-// );
|
76
|
|
-// }
|
77
|
|
-// }
|
78
|
|
-
|
79
|
|
-
|
|
109
|
+}
|