|
@@ -1,25 +1,73 @@
|
|
1
|
+import 'dart:convert';
|
1
|
2
|
import 'package:flutter/material.dart';
|
2
|
3
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
3
|
4
|
import 'package:get/get.dart';
|
|
5
|
+import 'package:worker_client/models/app.dart';
|
4
|
6
|
import 'package:worker_client/models/entities/Machinery.dart';
|
|
7
|
+import 'package:worker_client/services/amap.dart';
|
5
|
8
|
import 'package:worker_client/services/machinery.dart';
|
6
|
9
|
import 'package:worker_client/widgets/amap/amap.dart';
|
7
|
10
|
import 'package:worker_client/widgets/layout/BasicPage.dart';
|
8
|
|
-import 'package:amap_flutter_base/amap_flutter_base.dart';
|
9
|
11
|
|
10
|
12
|
class MachineryMap extends BasicPage {
|
11
|
13
|
MachineryMap({Key? key}) : super(key: key);
|
|
14
|
+ String? location = AppController.t.locationStr;
|
12
|
15
|
final machineryList = Rx<List<Machinery>>([]);
|
|
16
|
+ //用来放地图中心的
|
13
|
17
|
final machinery = Rx<Machinery>(Machinery());
|
|
18
|
+ //切换农机时用的当前农机变量
|
|
19
|
+ final current = Rx<Machinery>(Machinery());
|
|
20
|
+ final visible = Rx<bool>(true);
|
14
|
21
|
|
|
22
|
+ dynamic locList = [
|
|
23
|
+ '32.685927, 112.106514',
|
|
24
|
+ '32.673406, 112.100406',
|
|
25
|
+ '32.670488, 112.06397',
|
|
26
|
+ '32.685684, 112.05434',
|
|
27
|
+ '32.701302, 112.058724',
|
|
28
|
+ '32.665504, 112.015102',
|
|
29
|
+ '32.685502, 112.010503',
|
|
30
|
+ '32.651764, 112.097747',
|
|
31
|
+ '32.664957, 112.149705',
|
|
32
|
+ '32.701241, 112.16185',
|
|
33
|
+ ];
|
15
|
34
|
@override
|
16
|
35
|
void beforeShow() {
|
17
|
36
|
super.beforeShow();
|
18
|
37
|
if (Get.arguments != null) {
|
19
|
38
|
getMachineryDetail(Get.arguments['id'], {
|
20
|
39
|
'attached': true,
|
|
40
|
+ //查询农机详情时需要把当前定位传到服务端
|
21
|
41
|
'location': '118.84002,31.95266'
|
22
|
|
- }).then((res) => {machinery(Machinery.fromJson(res))});
|
|
42
|
+ }).then((res) => {
|
|
43
|
+ getMachineryList({'pageSize': 500, 'location': location})
|
|
44
|
+ .then((value) {
|
|
45
|
+ dynamic list = <Machinery>[];
|
|
46
|
+ int index;
|
|
47
|
+ Machinery data = Machinery.fromJson(res);
|
|
48
|
+ List area = [];
|
|
49
|
+ value['records'].forEach((item) {
|
|
50
|
+ index = value['records'].indexOf(item);
|
|
51
|
+ item['location'] = locList[index % 10];
|
|
52
|
+ list.add(Machinery.fromJson(item));
|
|
53
|
+ if (data.machineryId == item['machineryId']) {
|
|
54
|
+ data.location = item['location'];
|
|
55
|
+ area = item['location'].toString().split(',');
|
|
56
|
+ setAmap({
|
|
57
|
+ 'params': 'location=${area[1]},${area[0]}',
|
|
58
|
+ 'path': '/v3/geocode/regeo'
|
|
59
|
+ }).then((value) {
|
|
60
|
+ //json字符串转Map对象
|
|
61
|
+ data.address =
|
|
62
|
+ jsonDecode(value)['regeocode']['formatted_address'];
|
|
63
|
+ machinery(data);
|
|
64
|
+ current(data);
|
|
65
|
+ });
|
|
66
|
+ }
|
|
67
|
+ });
|
|
68
|
+ machineryList(list);
|
|
69
|
+ }),
|
|
70
|
+ });
|
23
|
71
|
}
|
24
|
72
|
}
|
25
|
73
|
|
|
@@ -29,97 +77,134 @@ class MachineryMap extends BasicPage {
|
29
|
77
|
|
30
|
78
|
void goDetail() {
|
31
|
79
|
Get.toNamed('/machineryDetail',
|
32
|
|
- arguments: {'id': machinery.value.machineryId});
|
|
80
|
+ arguments: {'id': current.value.machineryId});
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ void onClick(e) {
|
|
84
|
+ List area = e.location.toString().split(',');
|
|
85
|
+ if (e.address == null) {
|
|
86
|
+ setAmap({
|
|
87
|
+ //定位有问题
|
|
88
|
+ 'params': 'location=${area[1]},${area[0]}',
|
|
89
|
+ 'path': '/v3/geocode/regeo'
|
|
90
|
+ }).then((value) {
|
|
91
|
+ //json字符串转Map对象
|
|
92
|
+ e.address = jsonDecode(value)['regeocode']['formatted_address'];
|
|
93
|
+ current(e);
|
|
94
|
+ visible(true);
|
|
95
|
+ });
|
|
96
|
+ } else {
|
|
97
|
+ current(e);
|
|
98
|
+ visible(true);
|
|
99
|
+ }
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ void onCancel() {
|
|
103
|
+ if (!visible.value) {
|
|
104
|
+ visible(false);
|
|
105
|
+ }
|
33
|
106
|
}
|
34
|
107
|
|
35
|
|
- final LatLng position = const LatLng(32.690712, 112.091892);
|
36
|
108
|
@override
|
37
|
109
|
Widget builder(BuildContext context) {
|
38
|
110
|
naviTitle = '我的农机';
|
|
111
|
+
|
39
|
112
|
return Stack(
|
40
|
113
|
children: [
|
41
|
114
|
SizedBox(
|
42
|
115
|
width: 375.w,
|
43
|
|
- child: AMap(position: position),
|
|
116
|
+ child: Obx(
|
|
117
|
+ () => AMap(
|
|
118
|
+ machineryList: machineryList.value,
|
|
119
|
+ machinery: machinery.value,
|
|
120
|
+ onCancel: onCancel,
|
|
121
|
+ onClick: onClick,
|
|
122
|
+ ),
|
|
123
|
+ ),
|
44
|
124
|
),
|
45
|
|
- Positioned(
|
46
|
|
- bottom: 0,
|
47
|
|
- child: Container(
|
48
|
|
- width: 375.w,
|
49
|
|
- padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 30.h),
|
50
|
|
- decoration: BoxDecoration(
|
51
|
|
- borderRadius: BorderRadius.only(
|
52
|
|
- topLeft: Radius.circular(20.w),
|
53
|
|
- topRight: Radius.circular(20.w)),
|
54
|
|
- color: Colors.white),
|
55
|
|
- child: Column(
|
56
|
|
- crossAxisAlignment: CrossAxisAlignment.start,
|
57
|
|
- children: [
|
58
|
|
- GestureDetector(
|
59
|
|
- onTap: () {
|
60
|
|
- goBack();
|
61
|
|
- },
|
62
|
|
- child: Text(
|
63
|
|
- '<<农机列表',
|
64
|
|
- style: TextStyle(
|
65
|
|
- color: const Color(0xff666666),
|
66
|
|
- fontSize: 15.sp,
|
67
|
|
- fontWeight: FontWeight.bold),
|
68
|
|
- ),
|
69
|
|
- ),
|
70
|
|
- Container(
|
71
|
|
- margin: EdgeInsets.only(top: 30.h, bottom: 20.h),
|
72
|
|
- child: Row(
|
73
|
|
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
74
|
|
- children: [
|
75
|
|
- Text(
|
76
|
|
- '第一台收割机',
|
|
125
|
+ Obx(
|
|
126
|
+ () => Visibility(
|
|
127
|
+ visible: visible.value,
|
|
128
|
+ child: Positioned(
|
|
129
|
+ bottom: 0,
|
|
130
|
+ child: Container(
|
|
131
|
+ width: 375.w,
|
|
132
|
+ padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 30.h),
|
|
133
|
+ decoration: BoxDecoration(
|
|
134
|
+ borderRadius: BorderRadius.only(
|
|
135
|
+ topLeft: Radius.circular(20.w),
|
|
136
|
+ topRight: Radius.circular(20.w)),
|
|
137
|
+ color: Colors.white),
|
|
138
|
+ child: Column(
|
|
139
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
140
|
+ children: [
|
|
141
|
+ GestureDetector(
|
|
142
|
+ onTap: () {
|
|
143
|
+ goBack();
|
|
144
|
+ },
|
|
145
|
+ child: Text(
|
|
146
|
+ '<<农机列表',
|
77
|
147
|
style: TextStyle(
|
78
|
|
- color: const Color(0xff222222),
|
79
|
|
- fontSize: 18.sp,
|
|
148
|
+ color: const Color(0xff666666),
|
|
149
|
+ fontSize: 15.sp,
|
80
|
150
|
fontWeight: FontWeight.bold),
|
81
|
151
|
),
|
82
|
|
- GestureDetector(
|
83
|
|
- onTap: () {
|
84
|
|
- goDetail();
|
85
|
|
- },
|
86
|
|
- child: Text(
|
87
|
|
- '详情>>',
|
88
|
|
- style: TextStyle(
|
89
|
|
- color: const Color(0xff666666),
|
90
|
|
- fontSize: 15.sp,
|
91
|
|
- fontWeight: FontWeight.bold),
|
92
|
|
- ),
|
93
|
|
- )
|
94
|
|
- ],
|
95
|
|
- ),
|
96
|
|
- ),
|
97
|
|
- Row(
|
98
|
|
- children: [
|
|
152
|
+ ),
|
99
|
153
|
Container(
|
100
|
|
- margin: EdgeInsets.only(right: 8.w),
|
101
|
|
- child: Image.asset(
|
102
|
|
- 'images/index/position.png',
|
103
|
|
- width: 17.w,
|
|
154
|
+ margin: EdgeInsets.only(top: 30.h, bottom: 20.h),
|
|
155
|
+ child: Row(
|
|
156
|
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
157
|
+ children: [
|
|
158
|
+ Text(
|
|
159
|
+ current.value.name.toString(),
|
|
160
|
+ style: TextStyle(
|
|
161
|
+ color: const Color(0xff222222),
|
|
162
|
+ fontSize: 18.sp,
|
|
163
|
+ fontWeight: FontWeight.bold),
|
|
164
|
+ ),
|
|
165
|
+ GestureDetector(
|
|
166
|
+ onTap: () {
|
|
167
|
+ goDetail();
|
|
168
|
+ },
|
|
169
|
+ child: Text(
|
|
170
|
+ '详情>>',
|
|
171
|
+ style: TextStyle(
|
|
172
|
+ color: const Color(0xff666666),
|
|
173
|
+ fontSize: 15.sp,
|
|
174
|
+ fontWeight: FontWeight.bold),
|
|
175
|
+ ),
|
|
176
|
+ )
|
|
177
|
+ ],
|
104
|
178
|
),
|
105
|
179
|
),
|
106
|
|
- Expanded(
|
107
|
|
- flex: 1,
|
108
|
|
- child: Text(
|
109
|
|
- '当前位置: 江苏省南京市南京南站城际空间站D2栋212南京云致科技服务有限公司',
|
110
|
|
- style: TextStyle(
|
111
|
|
- fontWeight: FontWeight.bold,
|
112
|
|
- fontSize: 15.sp,
|
113
|
|
- color: const Color(0xff222222),
|
|
180
|
+ Row(
|
|
181
|
+ children: [
|
|
182
|
+ Container(
|
|
183
|
+ margin: EdgeInsets.only(right: 8.w),
|
|
184
|
+ child: Image.asset(
|
|
185
|
+ 'images/index/position.png',
|
|
186
|
+ width: 17.w,
|
|
187
|
+ ),
|
114
|
188
|
),
|
115
|
|
- ),
|
116
|
|
- )
|
|
189
|
+ Expanded(
|
|
190
|
+ flex: 1,
|
|
191
|
+ child: Text(
|
|
192
|
+ '当前位置:${current.value.address ?? ''.toString()}',
|
|
193
|
+ style: TextStyle(
|
|
194
|
+ fontWeight: FontWeight.bold,
|
|
195
|
+ fontSize: 15.sp,
|
|
196
|
+ color: const Color(0xff222222),
|
|
197
|
+ ),
|
|
198
|
+ ),
|
|
199
|
+ ),
|
|
200
|
+ ],
|
|
201
|
+ ),
|
117
|
202
|
],
|
118
|
|
- )
|
119
|
|
- ],
|
|
203
|
+ ),
|
|
204
|
+ ),
|
120
|
205
|
),
|
121
|
206
|
),
|
122
|
|
- )
|
|
207
|
+ ),
|
123
|
208
|
],
|
124
|
209
|
);
|
125
|
210
|
}
|