[baozhangchao] 3 years ago
parent
commit
0321f65622
4 changed files with 161 additions and 61 deletions
  1. BIN
      images/icons/starOff.png
  2. BIN
      images/icons/starOn.png
  3. 145
    61
      lib/pages/MoreCars/index.dart
  4. 16
    0
      lib/services/homeAPI.dart

BIN
images/icons/starOff.png View File


BIN
images/icons/starOn.png View File


+ 145
- 61
lib/pages/MoreCars/index.dart View File

1
+import 'dart:convert';
2
+
1
 import 'package:farmer_client/pages/home/widgets/home/widgets/headers.dart';
3
 import 'package:farmer_client/pages/home/widgets/home/widgets/headers.dart';
2
 import 'package:flutter/material.dart';
4
 import 'package:flutter/material.dart';
3
 import 'package:flutter_screenutil/flutter_screenutil.dart';
5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
4
 import 'package:get/get.dart';
6
 import 'package:get/get.dart';
5
 
7
 
8
+import '../../models/app.dart';
9
+import '../../models/entities/CardListModel.dart';
6
 import '../../models/entities/CardTypeModel.dart';
10
 import '../../models/entities/CardTypeModel.dart';
7
 import '../../services/homeAPI.dart';
11
 import '../../services/homeAPI.dart';
8
 import '../../widgets/CarsCard.dart';
12
 import '../../widgets/CarsCard.dart';
13
+import '../../widgets/NullCard.dart';
9
 import '../../widgets/Search.dart';
14
 import '../../widgets/Search.dart';
10
 
15
 
11
 class MoreCars extends StatefulWidget {
16
 class MoreCars extends StatefulWidget {
12
   const MoreCars({Key? key}) : super(key: key);
17
   const MoreCars({Key? key}) : super(key: key);
13
-
14
   @override
18
   @override
15
   State<MoreCars> createState() => _MoreCarsState();
19
   State<MoreCars> createState() => _MoreCarsState();
16
 }
20
 }
17
 
21
 
18
 class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
22
 class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
19
-   late TabController _controller = TabController(length: tabText.value.length, vsync: this);
23
+  late TabController _controller;
20
   final tabText = Rx<List<CardTypeModel>>([]);
24
   final tabText = Rx<List<CardTypeModel>>([]);
25
+  final classId = Rx<List<dynamic>>([]);
26
+    final cardTypeList = Rx<List<CardListModel>>([]);
27
+
28
+    String? location = AppController.t.locationStr;
29
+    late  int _selectedIndex;
30
+bool hasTopLoad=false;
21
 
31
 
22
 
32
 
23
 
33
 
25
   void initState() {
35
   void initState() {
26
     // TODO: implement initState
36
     // TODO: implement initState
27
     super.initState();
37
     super.initState();
38
+    // _controller.addListener(() {
39
+    //   setState(() => _selectedIndex = _controller.index);
40
+    //   print("liucheng-> ${_controller.indexIsChanging}");
41
+    // });
42
+    _controller=TabController(length: tabText.value.length, vsync: this);
43
+    _geList();
44
+    _getAllCarsList();
45
+
46
+
47
+
48
+  }
49
+  @override
50
+  void dispose() {
51
+    super.dispose();
52
+    _controller.dispose();
53
+  }
28
 
54
 
55
+  void _getAllCarsList (){
56
+    getMachinery(location??'112.087465,32.687507').then((value) {
57
+      final list = <CardListModel>[];
58
+      value['records'].forEach((item) {
59
+        list.add(CardListModel.fromJson(item));
60
+      });
61
+      cardTypeList(list);
62
+    });
29
   }
63
   }
30
   void _geList (){
64
   void _geList (){
31
     getMachineryType().then((value) {
65
     getMachineryType().then((value) {
32
       final list = <CardTypeModel>[];
66
       final list = <CardTypeModel>[];
33
-      List<String> newTabs =['全部'];
67
+      List classtypeId =[];
68
+      List <CardTypeModel> newTabs =[CardTypeModel.fromJson({'name':'全部'})];
34
       value['records'].forEach((item) {
69
       value['records'].forEach((item) {
35
         list.add(CardTypeModel.fromJson(item));
70
         list.add(CardTypeModel.fromJson(item));
36
-
37
       });
71
       });
72
+      list.insertAll(0, newTabs);
38
       tabText(list);
73
       tabText(list);
74
+      tabText().forEach((item) {
75
+        classtypeId.add( item.typeId);
76
+        String a=json.encode(classtypeId);
77
+        print(a);
78
+
79
+      });
80
+      classId(classtypeId);
81
+
82
+      hasTopLoad = true;
83
+      _controller =  TabController(length: tabText.value.length, vsync: this);
84
+      print(hasTopLoad);
85
+
86
+
39
     });
87
     });
40
   }
88
   }
41
 
89
 
90
+
91
+  void _handleTabChange(i){
92
+    final index=i;
93
+    if(index==0){
94
+      _getAllCarsList();
95
+    }else {
96
+      final typeId = classId.value[index];
97
+      typeMachinery(location ?? '112.087465,32.687507', typeId.toString())
98
+          .then((value) {
99
+        final list = <CardListModel>[];
100
+        value['records'].forEach((item) {
101
+          list.add(CardListModel.fromJson(item));
102
+        });
103
+        cardTypeList(list);
104
+
105
+      });
106
+    }
107
+
108
+
109
+  }
110
+
42
   @override
111
   @override
43
   Widget build(BuildContext context) {
112
   Widget build(BuildContext context) {
44
-    // _controller=TabController(length: tabText.length, vsync: this);
45
-    return Scaffold(
46
-        resizeToAvoidBottomInset: false,
47
-        appBar: AppBar(
48
-          centerTitle: true,
49
-          backgroundColor: Colors.transparent,
50
-          foregroundColor: const Color(0xFF333333),
51
-          elevation: 0,
52
-          toolbarHeight: 44.w,
53
-          title: Text(
54
-            '更多',
55
-            style: TextStyle(
56
-                color: const Color(0xFF333333),
57
-                fontWeight: FontWeight.bold,
58
-                fontSize: 17.sp,
59
-                letterSpacing: 2),
113
+
114
+      return Scaffold(
115
+          resizeToAvoidBottomInset: false,
116
+          appBar: AppBar(
117
+            centerTitle: true,
118
+            backgroundColor: Colors.transparent,
119
+            foregroundColor: const Color(0xFF333333),
120
+            elevation: 0,
121
+            toolbarHeight: 44.w,
122
+            title: Text(
123
+              '更多',
124
+              style: TextStyle(
125
+                  color: const Color(0xFF333333),
126
+                  fontWeight: FontWeight.bold,
127
+                  fontSize: 17.sp,
128
+                  letterSpacing: 2),
129
+            ),
60
           ),
130
           ),
61
-        ),
62
-        body: SafeArea(
63
-            child: Container(
64
-          decoration: BoxDecoration(color: Colors.white),
65
-          child: ListView(children: [
66
-            Column(
67
-              children: [
68
-                Container(
69
-                  padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
70
-                  width: 350.w,
71
-                  child: TypeHeader(
72
-                    type: false,
73
-                  ),
74
-                ),
75
-                TabBar(
76
-                  labelStyle: TextStyle(
77
-                      fontSize: ScreenUtil().setSp(19),
78
-                      fontWeight: FontWeight.bold), //选中的样式
79
-                  unselectedLabelStyle:
80
-                      TextStyle(fontSize: ScreenUtil().setSp(16)), //未选中的样式
81
-                  controller: _controller,
82
-                  isScrollable: true, //可滚动
83
-                  indicatorColor: Colors.black, //指示器的颜色
84
-                  labelColor: Colors.black, //选中文字颜色
85
-                  unselectedLabelColor: Color(0xffadadad),
86
-                  // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
87
-                  tabs: tabText.value.map((e) => Tab(text: e.name.toString())).toList(),
88
-                  onTap: (int i) {
89
-                    print('当前+${i}');
90
-                  },
91
-                ),
92
-                Container(
93
-                  child: Column(
94
-                    children: [],
95
-                  ),
96
-                )
97
-              ],
98
-            )
99
-          ]),
100
-        )));
101
-  }
131
+          body: SafeArea(
132
+              child: Container(
133
+                alignment: Alignment.center,
134
+                decoration: BoxDecoration(color: Colors.white),
135
+                child: !hasTopLoad?
136
+                ListView(children: [
137
+                  Column(
138
+                    children: [
139
+                      Container(
140
+                        padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
141
+                        width: 350.w,
142
+                        child: TypeHeader(
143
+                          type: false,
144
+                        ),
145
+                      ),
146
+                      Obx(() =>
147
+                          TabBar(
148
+                            labelStyle: TextStyle(
149
+                                fontSize: ScreenUtil().setSp(19),
150
+                                fontWeight: FontWeight.bold),
151
+                            //选中的样式
152
+                            unselectedLabelStyle:
153
+                            TextStyle(fontSize: ScreenUtil().setSp(16)),
154
+                            //未选中的样式
155
+                            controller: _controller,
156
+                            isScrollable: true,
157
+                            //可滚动
158
+                            indicatorColor: Colors.black,
159
+                            //指示器的颜色
160
+                            labelColor: Colors.black,
161
+                            //选中文字颜色
162
+                            unselectedLabelColor: Color(0xffadadad),
163
+                            // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
164
+                            tabs: tabText.value.map((e) =>
165
+                                Tab(text: e.name.toString())).toList(),
166
+                            onTap: (int i) {
167
+                              _handleTabChange(i);
168
+                            },
169
+                          )),
170
+                      Container(
171
+                        child: Obx(() =>
172
+                            Column(
173
+                              children:
174
+                              cardTypeList.value.length > 0 ?
175
+                              cardTypeList()
176
+                                  .map((item) => CarsCard(item: item))
177
+                                  .toList()
178
+                                  : [NullCard(text: '暂无农机信息!')],
179
+                            )),
180
+                      )
181
+                    ],
182
+                  )
183
+                ]):Text('加载中...'),
184
+              )));
185
+    }
102
 }
186
 }

+ 16
- 0
lib/services/homeAPI.dart View File

44
 
44
 
45
 
45
 
46
 
46
 
47
+
48
+/**
49
+ * 农机分类
50
+ * @param {*} data
51
+ * @returns
52
+ */
53
+Future typeMachinery(String location,String typeId,) async {
54
+  return request('/machinery', options: Options(method: 'GET'), queryParameters: {
55
+    'location': location,'typeId':typeId,
56
+  },data: {'typeId':typeId,'location':location}).catchError((error) => {
57
+    Fluttertoast.showToast(msg: error.error['message']),
58
+  });
59
+}
60
+
61
+
62
+
47
 /**
63
 /**
48
  * 农机详情
64
  * 农机详情
49
  * @param {*} data
65
  * @param {*} data