|
@@ -3,7 +3,9 @@ import 'dart:convert';
|
3
|
3
|
import 'package:farmer_client/pages/home/widgets/home/widgets/headers.dart';
|
4
|
4
|
import 'package:flutter/material.dart';
|
5
|
5
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
6
|
+import 'package:flutter_easyrefresh/easy_refresh.dart';
|
6
|
7
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
8
|
+import 'package:fluttertoast/fluttertoast.dart';
|
7
|
9
|
import 'package:get/get.dart';
|
8
|
10
|
|
9
|
11
|
import '../../models/app.dart';
|
|
@@ -22,52 +24,64 @@ class MoreCars extends StatefulWidget {
|
22
|
24
|
|
23
|
25
|
class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
|
24
|
26
|
late TabController _controller;
|
|
27
|
+ late EasyRefreshController _controllerList;
|
|
28
|
+
|
25
|
29
|
final tabText = Rx<List<CardTypeModel>>([]);
|
26
|
30
|
final classId = Rx<List<dynamic>>([]);
|
27
|
31
|
final cardTypeList = Rx<List<CardListModel>>([]);
|
28
|
|
-
|
|
32
|
+ final newCardTypeList = Rx<List<CardListModel>>([]);
|
|
33
|
+ var pageIndex = 1; //页数
|
|
34
|
+ var count = 10; //每页10条
|
|
35
|
+ late int maxSum; //最多条数
|
|
36
|
+ String value=''; //最多条数
|
|
37
|
+ int _count = 0;
|
29
|
38
|
String? location = AppController.t.locationStr;
|
30
|
|
- late int _selectedIndex;
|
31
|
39
|
bool hasTopLoad = false;
|
32
|
40
|
int index = 0;
|
|
41
|
+ String typeId='';
|
|
42
|
+ Map<String, dynamic> params = {'pageNum': 1,'location':AppController.t.locationStr,'typeId':''};
|
33
|
43
|
|
34
|
44
|
@override
|
35
|
45
|
void initState() {
|
36
|
46
|
// TODO: implement initState
|
37
|
47
|
super.initState();
|
38
|
48
|
_controller = TabController(length: tabText.value.length, vsync: this);
|
|
49
|
+ _controllerList = EasyRefreshController();
|
|
50
|
+
|
39
|
51
|
// _controller.addListener(() {
|
40
|
52
|
// setState(() => _selectedIndex = _controller.index);
|
41
|
53
|
// print("liucheng-> ${_controller.indexIsChanging}");
|
42
|
54
|
// });
|
43
|
55
|
_geList();
|
44
|
|
-
|
45
|
|
- _getAllCarsList();
|
|
56
|
+ getNewData(params);
|
|
57
|
+ // _getAllCarsList();
|
46
|
58
|
}
|
47
|
59
|
|
48
|
60
|
@override
|
49
|
61
|
void dispose() {
|
50
|
62
|
super.dispose();
|
51
|
63
|
_controller.dispose();
|
|
64
|
+ _controllerList.dispose();
|
52
|
65
|
}
|
53
|
66
|
|
54
|
|
-//进来拿到全部农机
|
55
|
|
- void _getAllCarsList() {
|
56
|
|
- EasyLoading.show(status: '数据加载中...');
|
57
|
|
- Map<String, dynamic> params = {'pageNum': 1,'location':location};
|
58
|
67
|
|
|
68
|
+
|
|
69
|
+ void getNewData(Map? params) {
|
|
70
|
+ pageIndex = 1;
|
|
71
|
+ params!['pageNum'] = pageIndex;
|
|
72
|
+ print(params['pageNum']);
|
59
|
73
|
getMachinery(params).then((value) {
|
60
|
|
- final list = <CardListModel>[];
|
|
74
|
+ maxSum = value['total'];
|
|
75
|
+
|
|
76
|
+ List<CardListModel> list = [];
|
61
|
77
|
value['records'].forEach((item) {
|
62
|
78
|
list.add(CardListModel.fromJson(item));
|
63
|
79
|
});
|
64
|
80
|
cardTypeList(list);
|
65
|
|
- EasyLoading.dismiss();
|
66
|
|
-
|
|
81
|
+ newCardTypeList(list);
|
|
82
|
+ _count = cardTypeList.value.length;
|
67
|
83
|
});
|
68
|
84
|
}
|
69
|
|
-
|
70
|
|
- //全部农机分类
|
71
|
85
|
void _geList() {
|
72
|
86
|
getMachineryType().then((value) {
|
73
|
87
|
EasyLoading.show(status: '数据加载中...');
|
|
@@ -94,33 +108,46 @@ class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
|
94
|
108
|
|
95
|
109
|
});
|
96
|
110
|
}
|
97
|
|
-
|
|
111
|
+ void getMoreData(Map? params) {
|
|
112
|
+ pageIndex++;
|
|
113
|
+ params!['pageNum'] = pageIndex;
|
|
114
|
+ print(params['pageNum']);
|
|
115
|
+ searchMachinery(params).then((value) {
|
|
116
|
+ maxSum = value['total'];
|
|
117
|
+ List<CardListModel> list = [];
|
|
118
|
+ List<CardListModel> Newlist = [];
|
|
119
|
+ value['records'].forEach((item) {
|
|
120
|
+ list.add(CardListModel.fromJson(item));
|
|
121
|
+ });
|
|
122
|
+ newCardTypeList.value.addAll(list);
|
|
123
|
+ Newlist.addAll(newCardTypeList.value);
|
|
124
|
+ cardTypeList(Newlist);
|
|
125
|
+ _count = cardTypeList.value.length;
|
|
126
|
+ });
|
|
127
|
+ }
|
98
|
128
|
void _handleTabChange(i) {
|
99
|
129
|
index = i;
|
100
|
130
|
if (index == 0) {
|
101
|
|
- _getAllCarsList();
|
|
131
|
+ Map<String, dynamic> paramss = {'pageNum': 1,'location':location};
|
|
132
|
+ getNewData(paramss);
|
102
|
133
|
} else {
|
103
|
|
- final typeId = classId.value[index];
|
|
134
|
+ // final typeId = classId.value[index];
|
|
135
|
+ print('typeId+$typeId');
|
|
136
|
+ typeId=classId.value[index];
|
104
|
137
|
print('typeId+$typeId');
|
105
|
|
- EasyLoading.show(status: '数据加载中...');
|
106
|
138
|
|
107
|
|
- typeMachinery(location ?? '112.087465,32.687507', typeId.toString())
|
108
|
|
- .then((value) {
|
109
|
|
- final list = <CardListModel>[];
|
110
|
|
- value['records'].forEach((item) {
|
111
|
|
- list.add(CardListModel.fromJson(item));
|
112
|
|
- });
|
113
|
|
- cardTypeList(list);
|
114
|
|
- EasyLoading.dismiss();
|
115
|
139
|
|
116
|
|
- });
|
|
140
|
+ // Map<String, dynamic> params = {'pageNum': 1,'location':location,'typeId':typeId.toString()};
|
|
141
|
+ params['typeId']=classId.value[index];
|
|
142
|
+ getNewData(params);
|
|
143
|
+
|
117
|
144
|
}
|
118
|
145
|
}
|
119
|
146
|
|
120
|
147
|
@override
|
121
|
148
|
Widget build(BuildContext context) {
|
122
|
149
|
return Scaffold(
|
123
|
|
- resizeToAvoidBottomInset: false,
|
|
150
|
+ resizeToAvoidBottomInset: true,
|
124
|
151
|
appBar: AppBar(
|
125
|
152
|
centerTitle: true,
|
126
|
153
|
backgroundColor: Colors.transparent,
|
|
@@ -138,11 +165,14 @@ class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
|
138
|
165
|
),
|
139
|
166
|
body: SafeArea(
|
140
|
167
|
child: Container(
|
141
|
|
- alignment: Alignment.center,
|
142
|
|
- decoration: BoxDecoration(color: Colors.white),
|
143
|
|
- child: !hasTopLoad
|
144
|
|
- ? ListView(children: [
|
145
|
|
- Column(
|
|
168
|
+ alignment: Alignment.center,
|
|
169
|
+ decoration: BoxDecoration(color: Colors.white),
|
|
170
|
+ child: !hasTopLoad
|
|
171
|
+ ? Column(
|
|
172
|
+ children: [
|
|
173
|
+ ListView(
|
|
174
|
+ shrinkWrap: true,
|
|
175
|
+ physics: NeverScrollableScrollPhysics(),
|
146
|
176
|
children: [
|
147
|
177
|
Container(
|
148
|
178
|
padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
|
|
@@ -152,42 +182,76 @@ class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
|
152
|
182
|
),
|
153
|
183
|
),
|
154
|
184
|
Obx(() => TabBar(
|
155
|
|
- labelStyle: TextStyle(
|
156
|
|
- fontSize: ScreenUtil().setSp(19),
|
157
|
|
- fontWeight: FontWeight.bold),
|
158
|
|
- //选中的样式
|
159
|
|
- unselectedLabelStyle:
|
160
|
|
- TextStyle(fontSize: ScreenUtil().setSp(16)),
|
161
|
|
- //未选中的样式
|
162
|
|
- controller: _controller,
|
163
|
|
- isScrollable: true,
|
164
|
|
- //可滚动
|
165
|
|
- indicatorColor: Colors.black,
|
166
|
|
- //指示器的颜色
|
167
|
|
- labelColor: Colors.black,
|
168
|
|
- //选中文字颜色
|
169
|
|
- unselectedLabelColor: Color(0xffadadad),
|
170
|
|
- // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
|
171
|
|
- tabs: tabText.value
|
172
|
|
- .map((e) => Tab(text: e.name.toString()))
|
173
|
|
- .toList(),
|
174
|
|
- onTap: (int i) {
|
175
|
|
- _handleTabChange(i);
|
176
|
|
- },
|
177
|
|
- )),
|
178
|
|
- Container(
|
179
|
|
- child: Obx(() => Column(
|
180
|
|
- children: cardTypeList.value.length > 0
|
181
|
|
- ? cardTypeList()
|
182
|
|
- .map((item) => CarsCard(item: item))
|
183
|
|
- .toList()
|
184
|
|
- : [NullCard(text: '暂无农机信息!')],
|
185
|
|
- )),
|
186
|
|
- )
|
|
185
|
+ labelStyle: TextStyle(
|
|
186
|
+ fontSize: ScreenUtil().setSp(19),
|
|
187
|
+ fontWeight: FontWeight.bold),
|
|
188
|
+ //选中的样式
|
|
189
|
+ unselectedLabelStyle:
|
|
190
|
+ TextStyle(fontSize: ScreenUtil().setSp(16)),
|
|
191
|
+ //未选中的样式
|
|
192
|
+ controller: _controller,
|
|
193
|
+ isScrollable: true,
|
|
194
|
+ //可滚动
|
|
195
|
+ indicatorColor: Colors.black,
|
|
196
|
+ //指示器的颜色
|
|
197
|
+ labelColor: Colors.black,
|
|
198
|
+ //选中文字颜色
|
|
199
|
+ unselectedLabelColor: Color(0xffadadad),
|
|
200
|
+ // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
|
|
201
|
+ tabs: tabText.value
|
|
202
|
+ .map((e) => Tab(text: e.name.toString()))
|
|
203
|
+ .toList(),
|
|
204
|
+ onTap: (int i) {
|
|
205
|
+ _handleTabChange(i);
|
|
206
|
+ },
|
|
207
|
+ )),
|
187
|
208
|
],
|
|
209
|
+ ),
|
|
210
|
+ Expanded(
|
|
211
|
+ child: _buildListView(context),
|
188
|
212
|
)
|
189
|
|
- ])
|
190
|
|
- : Text('加载中...'),
|
191
|
|
- )));
|
|
213
|
+ ],
|
|
214
|
+ )
|
|
215
|
+ : Text('加载中...'),
|
|
216
|
+ )));
|
192
|
217
|
}
|
|
218
|
+ Widget _buildListView(BuildContext context) {
|
|
219
|
+ return EasyRefresh(
|
|
220
|
+ controller: _controllerList,
|
|
221
|
+ firstRefresh: true,
|
|
222
|
+ onRefresh: () async {
|
|
223
|
+ await Future.delayed(Duration(seconds: 1), () {
|
|
224
|
+ print("下拉刷新-----");
|
|
225
|
+ // Map<String, dynamic> params = {'pageNum': pageIndex,'location':AppController.t.locationStr,'q':value};
|
|
226
|
+
|
|
227
|
+ getNewData(params);
|
|
228
|
+ _controllerList.resetLoadState();
|
|
229
|
+ });
|
|
230
|
+ },
|
|
231
|
+ onLoad: () async {
|
|
232
|
+ await Future.delayed(Duration(seconds: 1), () {
|
|
233
|
+ if (_count == maxSum) {
|
|
234
|
+ Fluttertoast.showToast(msg: '暂无更多数据哦');
|
|
235
|
+ } else {
|
|
236
|
+ // Map<String, dynamic> params = {'pageNum': pageIndex,'location':AppController.t.locationStr,'q':value};
|
|
237
|
+
|
|
238
|
+ getMoreData(params);
|
|
239
|
+ }
|
|
240
|
+ _controllerList.finishLoad(noMore: _count >= maxSum);
|
|
241
|
+
|
|
242
|
+ });
|
|
243
|
+ },
|
|
244
|
+ child: Obx(
|
|
245
|
+ () => cardTypeList.value.length > 0
|
|
246
|
+ ?
|
|
247
|
+ Column(
|
|
248
|
+ mainAxisSize: MainAxisSize.min,
|
|
249
|
+ children: cardTypeList.value
|
|
250
|
+ .map((item) => CarsCard(item: item))
|
|
251
|
+ .toList(),
|
|
252
|
+ ): NullCard(text: '暂无农机信息!'),
|
|
253
|
+ ),
|
|
254
|
+ );
|
|
255
|
+ }
|
|
256
|
+
|
193
|
257
|
}
|