|
@@ -0,0 +1,109 @@
|
|
1
|
+import 'package:flutter/cupertino.dart';
|
|
2
|
+import 'package:flutter/material.dart';
|
|
3
|
+import 'package:get/get.dart';
|
|
4
|
+import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
5
|
+
|
|
6
|
+class Home extends StatefulWidget {
|
|
7
|
+ const Home({Key? key}) : super(key: key);
|
|
8
|
+
|
|
9
|
+ @override
|
|
10
|
+ _Home createState() => _Home();
|
|
11
|
+}
|
|
12
|
+
|
|
13
|
+class _Home extends State<Home> {
|
|
14
|
+ List images = [
|
|
15
|
+ ['images/index/index.png', 'images/index/indexActive.png'],
|
|
16
|
+ ['images/index/job.png', 'images/index/jobActive.png'],
|
|
17
|
+ ['images/index/user.png', 'images/index/userActive.png'],
|
|
18
|
+ ];
|
|
19
|
+
|
|
20
|
+ final List _titles = ['首页', '订单列表', '个人中心'];
|
|
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
|
+
|
|
62
|
+ @override
|
|
63
|
+ Widget build(BuildContext context) {
|
|
64
|
+ return Scaffold(
|
|
65
|
+ appBar: AppBar(
|
|
66
|
+ elevation: 0,
|
|
67
|
+ centerTitle: true,
|
|
68
|
+ backgroundColor: Colors.white,
|
|
69
|
+ title: Text(
|
|
70
|
+ '首页',
|
|
71
|
+ style: TextStyle(
|
|
72
|
+ color: Colors.black,
|
|
73
|
+ fontSize: 17.sp,
|
|
74
|
+ letterSpacing: 2,
|
|
75
|
+ fontWeight: FontWeight.bold
|
|
76
|
+ ),
|
|
77
|
+ ),
|
|
78
|
+ ),
|
|
79
|
+ body: _body[_tabIndex],
|
|
80
|
+ bottomNavigationBar: Container(
|
|
81
|
+ height: 65.h,
|
|
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
|
+ ),
|
|
107
|
+ );
|
|
108
|
+ }
|
|
109
|
+}
|