|
@@ -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
|
}
|