张延森 3 år sedan
förälder
incheckning
e95336728c

+ 1
- 0
android/app/build.gradle Visa fil

@@ -57,6 +57,7 @@ android {
57 57
     dependencies {
58 58
 //        implementation 'com.google.android.material:material:1.5.0'
59 59
         implementation('com.amap.api:3dmap:9.1.0')
60
+//        implementation('com.amap.api:location:6.1.0')
60 61
     }
61 62
 
62 63
     buildTypes {

Binär
images/index/newsOFFImages.png Visa fil


Binär
images/index/newsONImages.png Visa fil


+ 5
- 2
lib/pages/home/index.dart Visa fil

@@ -4,10 +4,13 @@ import './widgets/home/index.dart';
4 4
 
5 5
 
6 6
 class Home extends BasicPage {
7
+  Home({Key? key}) : super(key: key) {
8
+    tabIndex = 0;
9
+    naviTitle = '首页';
10
+  }
11
+
7 12
   @override
8 13
   Widget builder(BuildContext context) {
9
-    handleTabbar = 0;
10
-    naviTitle = '首页';
11 14
     return const HomePage();
12 15
   }
13 16
 }

+ 5
- 2
lib/pages/infomation/index.dart Visa fil

@@ -3,10 +3,13 @@ import 'package:farmer_client/widgets/layout/BasicPage.dart';
3 3
 import 'package:flutter/material.dart';
4 4
 
5 5
 class Infomation extends BasicPage {
6
+  Infomation({Key? key}) : super(key: key) {
7
+    tabIndex = 2;
8
+    naviTitle = '咨讯';
9
+  }
10
+
6 11
   @override
7 12
   Widget builder(BuildContext context) {
8
-    handleTabbar = 2;
9
-    naviTitle = '咨讯';
10 13
     return  Information();
11 14
   }
12 15
 }

+ 5
- 2
lib/pages/main/index.dart Visa fil

@@ -3,10 +3,13 @@ import 'package:farmer_client/widgets/layout/BasicPage.dart';
3 3
 import 'package:flutter/material.dart';
4 4
 
5 5
 class Main extends BasicPage {
6
+  Main({Key? key}) : super(key: key) {
7
+    tabIndex = 3;
8
+    naviTitle = '我的';
9
+  }
10
+
6 11
   @override
7 12
   Widget builder(BuildContext context) {
8
-    handleTabbar = 3;
9
-    naviTitle = '我的';
10 13
     return const MainPage();
11 14
   }
12 15
 }

+ 5
- 2
lib/pages/order/index.dart Visa fil

@@ -4,10 +4,13 @@ import './widgets/order/index.dart';
4 4
 
5 5
 
6 6
 class Order extends BasicPage {
7
+  Order({Key? key}) : super(key: key) {
8
+    tabIndex = 1;
9
+    naviTitle = '订单';
10
+  }
11
+
7 12
   @override
8 13
   Widget builder(BuildContext context) {
9
-    handleTabbar = 1;
10
-    naviTitle = '订单';
11 14
     return const OrderPage();
12 15
   }
13 16
 }

+ 11
- 0
lib/widgets/Dialog.dart Visa fil

@@ -0,0 +1,11 @@
1
+
2
+import 'package:flutter/widgets.dart';
3
+
4
+class Dialog extends StatelessWidget {
5
+  @override
6
+  Widget build(BuildContext context) {
7
+    // TODO: implement build
8
+    throw UnimplementedError();
9
+  }
10
+
11
+}

+ 9
- 113
lib/widgets/layout/BasicPage.dart Visa fil

@@ -1,28 +1,28 @@
1 1
 
2
+import 'package:farmer_client/widgets/layout/bottomBar/BottomBar.dart';
2 3
 import 'package:flutter/material.dart';
3 4
 import 'package:flutter_screenutil/flutter_screenutil.dart';
4 5
 import 'package:get/get.dart';
5 6
 
7
+import 'barList.dart';
8
+
6 9
 abstract class BasicPage extends StatefulWidget {
7 10
   // 导航标题
8 11
   // 用法 naviTitle = xxxx
9 12
   final _title = Rx<String>("");
10
-  final isTabBar = Rx<bool>(false);
11
-  final tabIndex =Rx<int>(0);
12
-
13 13
   set naviTitle(String t) {
14 14
     _title.value = t;
15 15
   }
16
-  set handleTabbar(int index) {
17
-    tabIndex.value=index;
18
-    isTabBar.value = true;
19
-  }
16
+
17
+  // 当前活动 tab
18
+  // 如果非 tab 页, 则不传
19
+  int? tabIndex;
20 20
 
21 21
   // 允许滚动 - 不是响应式的
22 22
   bool canScroll;
23 23
 
24 24
   //
25
-  BasicPage({Key? key, this.canScroll = true}) : super(key: key);
25
+  BasicPage({Key? key, this.canScroll = true, this.tabIndex }) : super(key: key);
26 26
 
27 27
   @protected
28 28
   Widget builder(BuildContext context);
@@ -99,110 +99,6 @@ class _BasicPageState extends State<BasicPage> {
99 99
     }
100 100
   }
101 101
 
102
-
103
-
104
-  final List _titles = ['首页', '订单', '资讯','我的'];
105
-  final tabTextStyleSelected = TextStyle(
106
-      color: const Color(0xFFFF703B),
107
-      fontSize: 15.sp,
108
-      fontWeight: FontWeight.bold); //选线卡选中字体颜色
109
-  final tabTextStyleNormal = TextStyle(
110
-      color: const Color(0xFF323232),
111
-      fontSize: 15.sp,
112
-      fontWeight: FontWeight.bold); //选项卡未选中字体颜色
113
-
114
-  TextStyle getTabTextStyle(int curIndex) {
115
-    //设置tabbar 选中和未选中的状态文本
116
-    if (curIndex == widget.tabIndex.value) {
117
-      return tabTextStyleSelected;
118
-    }
119
-    return tabTextStyleNormal;
120
-  }
121
-
122
-  // 切换底部选项卡,标题的变化设置
123
-  Text getTabTitle(int curIndex) {
124
-    return Text(_titles[curIndex], style: getTabTextStyle(curIndex));
125
-  }
126
-
127
-  List images = [
128
-    ['images/index/HomesOFFImgaes.png', 'images/index/HomesNOImgaes.png'],
129
-    ['images/index/OrdersOFFImgaes.png', 'images/index/OrdersNOImgaes.png'],
130
-    ['images/index/newsONImages.png', 'images/index/newsOFFImages.png'],
131
-    ['images/index/MineOFFImgaes.png', 'images/index/MineNOImgaes.png'],
132
-  ];
133
-  Image getTabIcon(int curIndex) {
134
-    //设置tabbar选中和未选中的状态图标
135
-    if (curIndex == widget.tabIndex.value) {
136
-      return Image.asset(
137
-        images[curIndex][1],
138
-        width: 22.w,
139
-        height: 22.w,
140
-      );
141
-    }
142
-    return Image.asset(
143
-      images[curIndex][0],
144
-      width: 22.w,
145
-      height: 22.w,
146
-    );
147
-  }
148
-
149
-  Image getTabImage(path) {
150
-    return Image.asset(path, width: 22.w, height: 22.w);
151
-  }
152
-
153
-  Widget tabBar(index) {
154
-    return GestureDetector(
155
-      behavior: HitTestBehavior.opaque,
156
-      onTap: () {
157
-        if(index!=widget.tabIndex.value){
158
-          if(index==0){
159
-            Get.offNamed('/');
160
-          }else if(index==1){
161
-            Get.offNamed('/order');
162
-          }else if(index==2){
163
-            Get.offNamed('/infomation');
164
-          }else{
165
-            Get.offNamed('/main');
166
-          }
167
-        }
168
-      },
169
-      child: Container(
170
-        width: 93.w,
171
-        height: 65.h,
172
-        child: Column(
173
-          children: [
174
-            getTabIcon(index),
175
-            Padding(
176
-              padding: EdgeInsets.fromLTRB(0, 6.h, 0, 0),
177
-              child: getTabTitle(index),
178
-            )
179
-          ],
180
-        ),
181
-      ),
182
-    );
183
-  }
184
-  Widget? _bottomBar(){
185
-    if(widget.isTabBar.value) {
186
-      return Container(
187
-      padding: EdgeInsets.fromLTRB(0, 7.h, 0, 7.h),
188
-      decoration: BoxDecoration(
189
-        color: const Color(0xFFFFFFFF),
190
-        boxShadow: [
191
-          BoxShadow(
192
-            color: const Color(0x14000000),
193
-            offset: Offset(0, -2.w),
194
-            blurRadius: 3.w,
195
-          ),
196
-        ],
197
-      ),
198
-      child: Row(
199
-        children:_titles.asMap().keys.map((index) =>tabBar(index)).toList(),
200
-      ),
201
-    );
202
-    } else {
203
-      return null;
204
-    }
205
-  }
206 102
   @override
207 103
   Widget build(BuildContext context) {
208 104
     return Scaffold(
@@ -210,7 +106,7 @@ class _BasicPageState extends State<BasicPage> {
210 106
       body: SafeArea(
211 107
         child: _buildChild(context),
212 108
       ),
213
-      bottomNavigationBar: _bottomBar(),
109
+      bottomNavigationBar: widget.tabIndex == null ? null : BottomBar(list: BarList, current: widget.tabIndex!),
214 110
     );
215 111
   }
216 112
 }

+ 32
- 0
lib/widgets/layout/barList.dart Visa fil

@@ -0,0 +1,32 @@
1
+
2
+import 'package:flutter/cupertino.dart';
3
+import 'package:flutter_screenutil/flutter_screenutil.dart';
4
+
5
+import 'bottomBar/item.dart';
6
+
7
+final BarList = <BarItem>[
8
+  BarItem(
9
+    label: '首页',
10
+    page: '/',
11
+    normal: Item (color: const Color(0xFF323232), fontSize: 15.sp, image: 'images/index/HomesOFFImgaes.png'),
12
+    selected: Item (color: const Color(0xFFFF703B), fontSize: 15.sp, image: 'images/index/HomesNOImgaes.png'),
13
+  ),
14
+  BarItem(
15
+    label: '订单',
16
+    page: '/order',
17
+    normal: Item (color: const Color(0xFF323232), fontSize: 15.sp, image: 'images/index/OrdersOFFImgaes.png'),
18
+    selected: Item (color: const Color(0xFFFF703B), fontSize: 15.sp, image: 'images/index/OrdersNOImgaes.png'),
19
+  ),
20
+  BarItem(
21
+    label: '资讯',
22
+    page: '/infomation',
23
+    normal: Item (color: const Color(0xFF323232), fontSize: 15.sp, image: 'images/index/newsOFFImages.png'),
24
+    selected: Item (color: const Color(0xFFFF703B), fontSize: 15.sp, image: 'images/index/newsONImages.png'),
25
+  ),
26
+  BarItem(
27
+    label: '我的',
28
+    page: '/main',
29
+    normal: Item (color: const Color(0xFF323232), fontSize: 15.sp, image: 'images/index/MineOFFImgaes.png'),
30
+    selected: Item (color: const Color(0xFFFF703B), fontSize: 15.sp, image: 'images/index/MineNOImgaes.png'),
31
+  ),
32
+];

+ 87
- 0
lib/widgets/layout/bottomBar/BottomBar.dart Visa fil

@@ -0,0 +1,87 @@
1
+
2
+import 'package:farmer_client/widgets/layout/bottomBar/item.dart';
3
+import 'package:flutter/widgets.dart';
4
+import 'package:flutter_screenutil/flutter_screenutil.dart';
5
+import 'package:get/get.dart';
6
+
7
+
8
+class BottomBarItem extends StatelessWidget {
9
+
10
+  final bool selected;
11
+  final BarItem data;
12
+
13
+  BottomBarItem({Key? key, required this.selected, required this.data }) : super(key: key);
14
+
15
+  @override
16
+  Widget build(BuildContext context) {
17
+    final image = selected ? data.selected.image : data.normal.image;
18
+    final color = selected ? data.selected.color : data.normal.color;
19
+    final fontSize = selected ? data.selected.fontSize : data.normal.fontSize;
20
+
21
+    final textStyle = TextStyle(color: color, fontSize: fontSize, fontWeight: FontWeight.bold);
22
+
23
+    return GestureDetector(
24
+      onTap: () {
25
+        if (!selected) {
26
+          Get.offNamed(data.page);
27
+        }
28
+      },
29
+      child: Column(
30
+        children: [
31
+          Expanded(
32
+            flex: 1,
33
+            child: Image.asset(image, fit: BoxFit.cover),
34
+          ),
35
+          Expanded(
36
+            flex: 1,
37
+            child: Center(
38
+              child: Text(data.label, style: textStyle),
39
+            ),
40
+          ),
41
+        ],
42
+      ),
43
+    );
44
+  }
45
+}
46
+
47
+class BottomBar extends StatelessWidget {
48
+
49
+  final int current;
50
+  List<BarItem> list;
51
+
52
+  BottomBar({ Key? key , required this.list, required this.current }) : super(key: key);
53
+
54
+  @override
55
+  Widget build(BuildContext context) {
56
+    return Container(
57
+      width: double.infinity,
58
+      height: 65.w,
59
+      padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 0),
60
+      decoration: BoxDecoration(
61
+        color: const Color(0xFFFFFFFF),
62
+        boxShadow: [
63
+          BoxShadow(
64
+            color: const Color(0x14000000),
65
+            offset: Offset(0, -2.w),
66
+            blurRadius: 3.w,
67
+          ),
68
+        ],
69
+      ),
70
+      child: Center(
71
+        child: Row(
72
+          children: [
73
+            ...list.map((item) {
74
+              int index = list.indexOf(item);
75
+
76
+              return Expanded(
77
+                  flex: 1,
78
+                  child: BottomBarItem(data: item, selected: current == index ),
79
+              );
80
+            })
81
+          ],
82
+        ),
83
+      ),
84
+    );
85
+  }
86
+
87
+}

+ 19
- 0
lib/widgets/layout/bottomBar/item.dart Visa fil

@@ -0,0 +1,19 @@
1
+
2
+import 'dart:ui';
3
+
4
+class Item {
5
+  double fontSize;
6
+  Color color;
7
+  String image;
8
+
9
+  Item({ required this.fontSize, required this.color, required this.image });
10
+}
11
+
12
+class BarItem {
13
+  String label;
14
+  String page;
15
+  Item normal;
16
+  Item selected;
17
+
18
+  BarItem ({ required this.label, required this.page, required this.normal, required this.selected });
19
+}

+ 1
- 0
pubspec.yaml Visa fil

@@ -46,6 +46,7 @@ dependencies:
46 46
   fluttertoast: ^8.0.9
47 47
   location: ^4.3.0
48 48
   amap_flutter_map: ^3.0.0
49
+  #  amap_flutter_location: ^3.0.0
49 50
   carousel_slider: ^4.0.0
50 51
 
51 52