Commit 2d61c21d1d25339763f7d4228464f1e3eb252ad0

Authored by weixin_45529955
1 parent 5f63e24a

地图增加定位返回、信息提示方式搜索、增加刷新上拉加载

@@ -46,6 +46,7 @@ @@ -46,6 +46,7 @@
46 android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" 46 android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
47 android:hardwareAccelerated="true" 47 android:hardwareAccelerated="true"
48 android:windowSoftInputMode="adjustResize" 48 android:windowSoftInputMode="adjustResize"
  49 + android:enableOnBackInvokedCallback="true"
49 > 50 >
50 51
51 52
1 -  
2 import 'dart:async'; 1 import 'dart:async';
3 2
4 import 'package:amap_map_fluttify/amap_map_fluttify.dart'; 3 import 'package:amap_map_fluttify/amap_map_fluttify.dart';
@@ -6,13 +5,20 @@ import 'package:flutter/cupertino.dart'; @@ -6,13 +5,20 @@ import 'package:flutter/cupertino.dart';
6 5
7 import 'package:flutter/material.dart'; 6 import 'package:flutter/material.dart';
8 import 'package:amap_search_fluttify/amap_search_fluttify.dart'; 7 import 'package:amap_search_fluttify/amap_search_fluttify.dart';
  8 +import 'package:flutter_easyrefresh/easy_refresh.dart';
  9 +
9 import 'package:flutter_screenutil/flutter_screenutil.dart'; 10 import 'package:flutter_screenutil/flutter_screenutil.dart';
  11 +import 'package:one_key/res/colors.dart';
10 import 'package:one_key/utils/dialog_util.dart'; 12 import 'package:one_key/utils/dialog_util.dart';
11 import 'package:one_key/utils/misc.dart'; 13 import 'package:one_key/utils/misc.dart';
12 import 'package:one_key/route/navigator_util.dart'; 14 import 'package:one_key/route/navigator_util.dart';
  15 +import 'package:one_key/utils/screen_util.dart';
13 import 'package:one_key/utils/utils.dart'; 16 import 'package:one_key/utils/utils.dart';
  17 +import 'package:one_key/widgets/h_empty_view.dart';
14 import 'package:one_key/widgets/system_app_bar.dart'; 18 import 'package:one_key/widgets/system_app_bar.dart';
15 import 'package:permission_handler/permission_handler.dart'; 19 import 'package:permission_handler/permission_handler.dart';
  20 +
  21 +import '../../utils/common_utils.dart';
16 // import 'package:demo/resources/custom_text_style.dart'; 22 // import 'package:demo/resources/custom_text_style.dart';
17 // import 'package:demo/utils/misc.dart'; 23 // import 'package:demo/utils/misc.dart';
18 24
@@ -40,23 +46,36 @@ class _MapChoicePointPageState extends State<MapChoicePointPage> { @@ -40,23 +46,36 @@ class _MapChoicePointPageState extends State<MapChoicePointPage> {
40 double latitude = 39.684670899; 46 double latitude = 39.684670899;
41 double longitude = 118.17630045; 47 double longitude = 118.17630045;
42 48
  49 + double latitudeLocation = 39.684670899;
  50 + double longitudeLocation = 118.17630045;
  51 +
  52 + List<InputTip> inputTipDatas = [];
  53 + int page = 1;
  54 + EasyRefreshController refreshController = EasyRefreshController();
  55 + bool flag = true;
  56 +
43 @override 57 @override
44 void initState() { 58 void initState() {
45 super.initState(); 59 super.initState();
46 60
47 - if (widget.long != null && widget.long != ''&&widget.long != 'null') { 61 + if (widget.long != null && widget.long != '' && widget.long != 'null') {
48 longitude = double.parse(widget.long!); 62 longitude = double.parse(widget.long!);
49 } 63 }
50 - if (widget.lat != null && widget.lat != ''&&widget.lat != 'null') { 64 + if (widget.lat != null && widget.lat != '' && widget.lat != 'null') {
51 latitude = double.parse(widget.lat!); 65 latitude = double.parse(widget.lat!);
52 } 66 }
53 67
54 WidgetsBinding.instance.addPostFrameCallback((_) async { 68 WidgetsBinding.instance.addPostFrameCallback((_) async {
55 _requestLocationPermission(); 69 _requestLocationPermission();
  70 +
  71 + // ama
  72 + // let marker = new AMap.Marker({//添加标记点
  73 + // position: this.position,
  74 + // map: map
56 }); 75 });
57 } 76 }
58 77
59 - Future<bool> checkLocationPermission() async { 78 + Future<bool> checkLocationPermission() async {
60 PermissionStatus permissionStatus = await Permission.location.status; 79 PermissionStatus permissionStatus = await Permission.location.status;
61 if (permissionStatus == PermissionStatus.granted) { 80 if (permissionStatus == PermissionStatus.granted) {
62 return true; 81 return true;
@@ -108,23 +127,30 @@ class _MapChoicePointPageState extends State<MapChoicePointPage> { @@ -108,23 +127,30 @@ class _MapChoicePointPageState extends State<MapChoicePointPage> {
108 { 127 {
109 // App.sp.setString("lat", "39.684670899"); 128 // App.sp.setString("lat", "39.684670899");
110 // App.sp.setString("lng", "118.17630045"); 129 // App.sp.setString("lng", "118.17630045");
111 -  
112 } else { 130 } else {
113 - if (widget.long == null || widget.long == ''||widget.long == 'null') { 131 + if (widget.long == null ||
  132 + widget.long == '' ||
  133 + widget.long == 'null') {
114 latitude = location.latLng!.latitude; 134 latitude = location.latLng!.latitude;
115 longitude = location.latLng!.longitude; 135 longitude = location.latLng!.longitude;
116 if (_controller != null) { 136 if (_controller != null) {
117 - _controller!.setCenterCoordinate(  
118 - LatLng(location.latLng!.latitude, location.latLng!.longitude)); 137 + _controller!.setCenterCoordinate(LatLng(
  138 + location.latLng!.latitude, location.latLng!.longitude));
119 } 139 }
120 140
  141 + page = 1;
  142 +
  143 + _loadData(
  144 + LatLng(location.latLng!.latitude, location.latLng!.longitude));
  145 +
121 setState(() {}); 146 setState(() {});
122 } 147 }
  148 + latitudeLocation = location.latLng!.latitude;
  149 + longitudeLocation = location.latLng!.longitude;
123 } 150 }
124 }); 151 });
125 } else { 152 } else {
126 //无权限 153 //无权限
127 -  
128 } 154 }
129 } 155 }
130 156
@@ -136,279 +162,485 @@ class _MapChoicePointPageState extends State<MapChoicePointPage> { @@ -136,279 +162,485 @@ class _MapChoicePointPageState extends State<MapChoicePointPage> {
136 '选择位置信息', 162 '选择位置信息',
137 onTap: () { 163 onTap: () {
138 if (Navigator.canPop(context)) { 164 if (Navigator.canPop(context)) {
139 - Navigator.pop(context); 165 + Navigator.pop(context);
140 } 166 }
141 }, 167 },
142 ), 168 ),
143 169
144 body: Column( 170 body: Column(
145 children: <Widget>[ 171 children: <Widget>[
146 - Theme(  
147 - data: new ThemeData(  
148 - primaryColor: Color(0xFFFFCA28), hintColor: Color(0xFFFFCA28)),  
149 - child: Container(  
150 - color: Color(0xFFFFCA28),  
151 - padding: EdgeInsets.all(5),  
152 - child: Container(  
153 - height: 36,  
154 - margin: EdgeInsets.only(left: 5, right: 5, bottom: 5),  
155 - child: TextField(  
156 - style: TextStyle(fontSize: 16, letterSpacing: 1.0),  
157 - controller: TextEditingController.fromValue(TextEditingValue(  
158 - // 设置内容  
159 - text: keyword,  
160 - selection: TextSelection.fromPosition(TextPosition(  
161 - affinity: TextAffinity.downstream,  
162 - offset: keyword.length)),  
163 - // 保持光标在最后  
164 - )),  
165 - decoration: InputDecoration(  
166 - border: OutlineInputBorder(  
167 - borderRadius: BorderRadius.all(Radius.circular(40)), 172 + // Theme(
  173 + // data: new
  174 + // ThemeData(
  175 + // // primaryColor: MyColours.color_438E93,
  176 + // // hintColor: MyColours.color_438E93),
  177 + // child:
  178 + // Container(
  179 + // color: MyColours.color_438E93,
  180 + // decoration: BoxDecoration(
  181 + // color: MyColours.color_438E93,
  182 + // boxShadow: [
  183 + // BoxShadow(color: Colors.white, spreadRadius: 1),
  184 + // ],
  185 + // ),
  186 +
  187 + // padding: EdgeInsets.all(5),
  188 + // child:
  189 +
  190 + // ),
  191 + // ),
  192 + // ListView.builder(
  193 + // shrinkWrap: true,
  194 + // itemCount: inputTipDatas.length,
  195 + // itemBuilder: (context, index) {
  196 + // InputTip inputTip = inputTipDatas[index];
  197 + // return InkWell(
  198 + // onTap: () {
  199 + // // searchAroundAddress(inputTip.name ?? '');
  200 + // // searchPoiId(inputTip.poiId ?? '');
  201 + // // _loadData(inputTip.coordinate ??
  202 + // // LatLng(latitude, longitude));
  203 + // },
  204 + // child: Container(
  205 + // child: Row(
  206 + // children: [
  207 + // Text(
  208 + // inputTip.name ?? '',
  209 + // style: TextStyle(
  210 + // fontSize: font(15),
  211 + // color: MyColours.color_515151),
  212 + // ),
  213 + // HEmptyView(10),
  214 + // Expanded(
  215 + // child: Text(
  216 + // (inputTip.district ?? '') +
  217 + // (inputTip.address ?? ''),
  218 + // style: TextStyle(
  219 + // fontSize: font(13),
  220 + // color: MyColours.color_999999),
  221 + // ),
  222 + // ),
  223 + // ],
  224 + // )));
  225 + // })
  226 + // ],
  227 + // ),
  228 +
  229 + Stack(
  230 + children: [
  231 + Container(
  232 + height: w(300),
  233 + child: Stack(
  234 + children: <Widget>[
  235 + AmapView(
  236 + showZoomControl: false,
  237 +
  238 + /// 是否显示指南针控件
  239 + showCompass: true,
  240 +
  241 + /// 是否显示比例尺控件
  242 + showScaleControl: true,
  243 +
  244 + /// 是否使能缩放手势
  245 + zoomGesturesEnabled: true,
  246 +
  247 + /// 是否使能滚动手势
  248 + scrollGesturesEnabled: true,
  249 +
  250 + /// 是否使能旋转手势
  251 + rotateGestureEnabled: false,
  252 + centerCoordinate: LatLng(latitude, longitude),
  253 + maskDelay: Duration(milliseconds: 500),
  254 + zoomLevel: 19,
  255 + onMapCreated: (controller) async {
  256 + _controller = controller;
  257 + _controller!
  258 + .setCenterCoordinate(LatLng(latitude, longitude));
  259 + // if (await requestPermission(PermissionGroup.location)) {
  260 + // await controller.showMyLocation(true);
  261 + // await controller?.showLocateControl(true);
  262 + // final latLng = await _controller?.getLocation(
  263 + // delay: Duration(seconds: 2));
  264 + // await enableFluttifyLog(false); // 关闭log
  265 + // _loadData(latLng);
  266 + // } else {
  267 + // //无权限
  268 + // _showLocPemWidget();
  269 + // }
  270 + },
  271 + // markers: [],
  272 + onMapMoveEnd: (MapMove move) async {
  273 + latitude = move.coordinate!.latitude;
  274 + longitude = move.coordinate!.longitude;
  275 + page = 1;
  276 + _loadData(move.coordinate!);
  277 + },
  278 + ),
  279 + Center(
  280 + child: Icon(
  281 + Icons.place,
  282 + size: w(32),
  283 + color: Color(0xFFFF0000),
  284 + ),
168 ), 285 ),
169 - hintText: '输入关键字',  
170 - hintStyle:  
171 - TextStyle(color: Color(0xFFBEBEBE), fontSize: 14),  
172 - contentPadding:  
173 - const EdgeInsets.symmetric(vertical: 8, horizontal: 1),  
174 - prefixIcon: Icon(  
175 - Icons.search,  
176 - color: Colors.grey,  
177 - size: 20, 286 + Positioned(
  287 + right: w(10),
  288 + bottom: w(10),
  289 + child: InkWell(
  290 + onTap: () {
  291 + _controller!.setCenterCoordinate(
  292 + LatLng(latitudeLocation, longitudeLocation));
  293 + },
  294 + child: Container(
  295 + decoration: BoxDecoration(
  296 + color: MyColours.color_ffffff,
  297 + borderRadius: BorderRadius.circular(r(5))),
  298 + padding: EdgeInsets.all(w(5)),
  299 + child: Image.asset(
  300 + Utils.getImgPath('location_map'),
  301 + width: w(25),
  302 + ),
  303 + )),
  304 + )
  305 + ],
  306 + ),
  307 + ),
  308 + Positioned(
  309 + top: w(10),
  310 + left: w(20),
  311 + right: w(20),
  312 + child: Container(
  313 + // height: w(45),
  314 + padding: EdgeInsets.symmetric(vertical: w(10)),
  315 + decoration: BoxDecoration(
  316 + color: Colors.white,
  317 + borderRadius: BorderRadius.circular(r(10))),
  318 + child: TextField(
  319 + textAlignVertical: TextAlignVertical.center,
  320 + style: TextStyle(
  321 + color: MyColours.color_515151,
  322 + fontSize: font(15),
178 ), 323 ),
179 - suffixIcon: IconButton(  
180 - icon: Icon(  
181 - Icons.clear,  
182 - color: Colors.grey,  
183 - size: 20, 324 + controller:
  325 + TextEditingController.fromValue(TextEditingValue(
  326 + // 设置内容
  327 + text: keyword,
  328 + selection: TextSelection.fromPosition(TextPosition(
  329 + affinity: TextAffinity.downstream,
  330 + offset: keyword.length)),
  331 + // 保持光标在最后
  332 + )),
  333 + decoration: InputDecoration(
  334 + // border: b,
  335 + // border: OutlineInputBorder(
  336 + // borderRadius: BorderRadius.all(Radius.circular(40)),
  337 + // ),
  338 + border: OutlineInputBorder(borderSide: BorderSide.none),
  339 + hintText: '输入关键字',
  340 + isCollapsed: true,
  341 +
  342 + hintStyle: TextStyle(
  343 + color: MyColours.color_999999, fontSize: font(15)),
  344 + // contentPadding: const EdgeInsets.symmetric(
  345 + // vertical: 8, horizontal: 1),
  346 + prefixIconConstraints: BoxConstraints(maxWidth: w(40)),
  347 + prefixIcon: Padding(
  348 + padding: EdgeInsets.only(left: w(10), right: w(10)),
  349 + child: SizedBox(
  350 + width: w(30),
  351 + child: Image.asset(
  352 + Utils.getImgPath('search_black'),
  353 + ))),
  354 + suffixIconConstraints: BoxConstraints(maxWidth: w(32)),
  355 + suffixIcon: InkWell(
  356 + child: Padding(
  357 + padding: EdgeInsets.only(left: w(10), right: w(10)),
  358 + child: SizedBox(
  359 + width: w(22),
  360 + child: Image.asset(
  361 + Utils.getImgPath('delete_black'),
  362 + ))),
  363 + onTap: () {
  364 + keyword = "";
  365 + setState(() {});
  366 + },
184 ), 367 ),
185 - onPressed: () {  
186 - keyword = "";  
187 - setState(() {});  
188 - }, 368 + fillColor: Colors.white,
  369 + filled: true,
189 ), 370 ),
190 - fillColor: Colors.white,  
191 - filled: true,  
192 - ),  
193 371
194 - inputFormatters: [],  
195 - //内容改变的回调  
196 - onChanged: (text) {  
197 - print('change $text');  
198 - keyword = text;  
199 - },  
200 - //内容提交(按回车)的回调  
201 - onSubmitted: (text) {  
202 - print('submit $text');  
203 - // 触发关闭弹出来的键盘。  
204 - keyword = text;  
205 - setState(() {  
206 - isloading = true; 372 + inputFormatters: [],
  373 + //内容改变的回调
  374 + onChanged: (text) {
  375 + print('change $text');
  376 + keyword = text;
  377 +
  378 + //搜索
  379 +
  380 + JhCommonUtils.debounce(
  381 + () => _fetchInputTips(text.toString()));
  382 + },
  383 + //内容提交(按回车)的回调
  384 + onSubmitted: (text) {
  385 + print('submit $text');
  386 + // 触发关闭弹出来的键盘。
  387 + keyword = text;
207 FocusScope.of(context).requestFocus(FocusNode()); 388 FocusScope.of(context).requestFocus(FocusNode());
208 - });  
209 -  
210 - searchAroundAddress(text.toString());  
211 - },  
212 - //按回车时调用  
213 - onEditingComplete: () {  
214 - print('onEditingComplete');  
215 - },  
216 - ),  
217 - ),  
218 - ),  
219 - ),  
220 - Container(  
221 - height: 300,  
222 - child: Stack(  
223 - children: <Widget>[  
224 - AmapView(  
225 - showZoomControl: false,  
226 - centerCoordinate: LatLng(latitude, longitude),  
227 - maskDelay: Duration(milliseconds: 500),  
228 - zoomLevel: 16,  
229 - onMapCreated: (controller) async {  
230 - _controller = controller;  
231 - _controller!  
232 - .setCenterCoordinate(LatLng(latitude, longitude));  
233 - // if (await requestPermission(PermissionGroup.location)) {  
234 - // await controller.showMyLocation(true);  
235 - // await controller?.showLocateControl(true);  
236 - // final latLng = await _controller?.getLocation(  
237 - // delay: Duration(seconds: 2));  
238 - // await enableFluttifyLog(false); // 关闭log  
239 - // _loadData(latLng);  
240 - // } else {  
241 - // //无权限  
242 - // _showLocPemWidget();  
243 - // }  
244 - },  
245 - onMapMoveEnd: (MapMove move) async {  
246 - _loadData(move.coordinate!);  
247 - },  
248 - ),  
249 - Center(  
250 - child: Icon(  
251 - Icons.place,  
252 - size: 36.0,  
253 - color: Color(0xFFFF0000), 389 + setState(() {
  390 + // isloading = true;
  391 + });
  392 +
  393 + // _fetchInputTips(text.toString());
  394 +
  395 + // searchAroundAddress(text.toString());
  396 + },
  397 + //按回车时调用
  398 + onEditingComplete: () {
  399 + print('onEditingComplete');
  400 + },
254 ), 401 ),
255 ), 402 ),
256 - ],  
257 - ), 403 + )
  404 + ],
258 ), 405 ),
  406 +
259 Expanded( 407 Expanded(
260 flex: 1, 408 flex: 1,
261 child: Visibility( 409 child: Visibility(
262 - visible: !isloading,  
263 - maintainSize: false,  
264 - maintainSemantics: false,  
265 - maintainInteractivity: false,  
266 - replacement: Center(  
267 - child: CupertinoActivityIndicator(),  
268 - ),  
269 - child: ListView.builder(  
270 - itemCount: list.length,  
271 - itemBuilder: (BuildContext context, int position) {  
272 - print("itemBuilder" + list.length.toString());  
273 - PoiModel item = list[position]!;  
274 - return InkWell(  
275 - child: Column(  
276 - children: <Widget>[  
277 - Container(  
278 - margin:  
279 - EdgeInsets.only(top: 8, bottom: 5, left: 10),  
280 - child: Row( 410 + visible: !isloading,
  411 + maintainSize: false,
  412 + maintainSemantics: false,
  413 + maintainInteractivity: false,
  414 + replacement: Center(
  415 + child: CupertinoActivityIndicator(),
  416 + ),
  417 + child: EasyRefresh.custom(
  418 + controller: refreshController,
  419 + slivers: [
  420 + SliverList(
  421 + delegate: SliverChildBuilderDelegate(
  422 + (BuildContext context, int position) {
  423 + print("itemBuilder" + list.length.toString());
  424 + PoiModel item = list[position]!;
  425 + return InkWell(
  426 + child: Column(
281 children: <Widget>[ 427 children: <Widget>[
282 - Icon(  
283 - Icons.place,  
284 - size: 20.0,  
285 - color: position == 0  
286 - ? Colors.green  
287 - : Colors.grey, 428 + Container(
  429 + margin: EdgeInsets.only(
  430 + top: 8, bottom: 5, left: 10),
  431 + child: Row(
  432 + children: <Widget>[
  433 + Icon(
  434 + Icons.place,
  435 + size: 20.0,
  436 + color: position == 0
  437 + ? Colors.green
  438 + : Colors.grey,
  439 + ),
  440 + Expanded(
  441 + child: Text(item.title,
  442 + style: TextStyle(
  443 + fontSize: 16,
  444 + color: position == 0
  445 + ? Colors.green
  446 + : Color(0xFF787878))))
  447 + ],
  448 + ),
  449 + ),
  450 + Container(
  451 + margin: EdgeInsets.only(
  452 + top: 5, bottom: 5, left: 18),
  453 + alignment: Alignment.centerLeft,
  454 + child: Text(
  455 + item.address!,
  456 + style: TextStyle(
  457 + fontSize: 14,
  458 + color: Color(0xFF646464),
  459 + ),
  460 + ),
288 ), 461 ),
289 - Expanded(  
290 - child: Text(item.title,  
291 - style: TextStyle(  
292 - fontSize: 16,  
293 - color: position == 0  
294 - ? Colors.green  
295 - : Color(0xFF787878)))) 462 + Divider(
  463 + height: 1,
  464 + )
296 ], 465 ],
297 ), 466 ),
298 - ),  
299 - Container(  
300 - margin:  
301 - EdgeInsets.only(top: 5, bottom: 5, left: 18),  
302 - alignment: Alignment.centerLeft,  
303 - child: Text(  
304 - item.address!,  
305 - style: TextStyle(  
306 - fontSize: 14,  
307 - color: Color(0xFF646464),  
308 - ),  
309 - ),  
310 - ),  
311 - Divider(  
312 - height: 1,  
313 - )  
314 - ], 467 + onTap: () async {
  468 + // await _controller.setCenterCoordinate(
  469 + // LatLng(item.latLng.latitude, item.latLng.longitude),
  470 + // zoomLevel: 16);
  471 + if (Navigator.canPop(context)) {
  472 + Navigator.pop(context, {
  473 + 'address': item.address,
  474 + 'lat': item.latLng!.latitude.toString(),
  475 + 'lng': item.latLng!.longitude.toString()
  476 + });
  477 + }
  478 + },
  479 + );
  480 + },
  481 + childCount: list.length,
315 ), 482 ),
316 - onTap: () async {  
317 - // await _controller.setCenterCoordinate(  
318 - // LatLng(item.latLng.latitude, item.latLng.longitude),  
319 - // zoomLevel: 16);  
320 - if (Navigator.canPop(context)) {  
321 - Navigator.pop(context, {  
322 - 'address': item.address,  
323 - 'lat': item.latLng!.latitude.toString(),  
324 - 'lng': item.latLng!.longitude.toString()  
325 - });  
326 - }  
327 - },  
328 - );  
329 - }),  
330 - ), 483 + )
  484 + ],
  485 + onRefresh: () async {
  486 + if (flag) {
  487 + page = 1;
  488 + _loadData(LatLng(latitude, longitude));
  489 + }
  490 + },
  491 + onLoad: () async {
  492 + if (flag) {
  493 + page++;
  494 + _loadData(LatLng(latitude, longitude),
  495 + showloading: false);
  496 + }
  497 + },
  498 + )),
331 ), 499 ),
332 ], 500 ],
333 ), 501 ),
334 ); 502 );
335 } 503 }
336 504
337 - void _loadData(LatLng latLng) async {  
338 - setState(() {  
339 - isloading = true;  
340 - }); 505 + _fetchInputTips(String text) async {
  506 + flag = false;
  507 + page = 1;
  508 + // setState(() {
  509 + // isloading = true;
  510 + // });
341 511
342 /// 逆地理编码(坐标转地址) 512 /// 逆地理编码(坐标转地址)
343 /// 513 ///
344 /// 514 ///
345 await AmapLocation.instance.updatePrivacyShow(true); 515 await AmapLocation.instance.updatePrivacyShow(true);
346 await AmapLocation.instance.updatePrivacyAgree(true); 516 await AmapLocation.instance.updatePrivacyAgree(true);
347 - ReGeocode reGeocodeList = await AmapSearch.instance.searchReGeocode(  
348 - latLng,  
349 - ); 517 +
  518 + LatLng latLng = LatLng(latitude, longitude);
  519 + ReGeocode reGeocodeList = await AmapSearch.instance.searchReGeocode(latLng);
350 520
351 // print(await reGeocodeList.toFutureString()); 521 // print(await reGeocodeList.toFutureString());
352 address = reGeocodeList.formatAddress; 522 address = reGeocodeList.formatAddress;
353 523
354 await AmapLocation.instance.updatePrivacyShow(true); 524 await AmapLocation.instance.updatePrivacyShow(true);
355 await AmapLocation.instance.updatePrivacyAgree(true); 525 await AmapLocation.instance.updatePrivacyAgree(true);
356 - final poiList = await AmapSearch.instance.searchAround(  
357 - latLng, 526 + inputTipDatas = await AmapSearch.instance.fetchInputTips(
  527 + text,
358 city: "", 528 city: "",
359 ); 529 );
  530 + print(inputTipDatas);
360 531
361 poiModel = new PoiModel("当前位置", address, latLng); 532 poiModel = new PoiModel("当前位置", address, latLng);
362 list.clear(); 533 list.clear();
363 list.add(poiModel); 534 list.add(poiModel);
364 - for (var poi in poiList) {  
365 - String? title = await poi.title;  
366 - String? cityName = await poi.cityName;  
367 - String? provinceName = await poi.provinceName;  
368 - String? address = await poi.address;  
369 - LatLng? latLng = await poi.latLng;  
370 - String? bussniss = poi.businessArea; 535 + for (var inputTip in inputTipDatas) {
  536 + String? title = await inputTip.name ?? '';
  537 + String? cityStr =
  538 + await (inputTip.district ?? '') + (inputTip.address ?? '');
371 539
372 - list.add(new PoiModel(  
373 - title.toString(),  
374 - provinceName.toString() +  
375 - cityName.toString() +  
376 - address.toString() +  
377 - bussniss.toString(),  
378 - latLng)); 540 + LatLng? latLng = await inputTip.coordinate;
  541 +
  542 + list.add(new PoiModel(title.toString(), cityStr, latLng));
379 } 543 }
380 544
381 setState(() { 545 setState(() {
382 - isloading = false; 546 + // isloading = false;
383 }); 547 });
384 } 548 }
385 549
386 - void searchAroundAddress(String text) async { 550 + void _loadData(LatLng latLng, {showloading = true}) async {
  551 + flag = true;
  552 + setState(() {
  553 + if (showloading) {
  554 + isloading = true;
  555 + }
  556 + });
  557 +
  558 + /// 逆地理编码(坐标转地址)
  559 + ///
  560 + ///
387 await AmapLocation.instance.updatePrivacyShow(true); 561 await AmapLocation.instance.updatePrivacyShow(true);
388 await AmapLocation.instance.updatePrivacyAgree(true); 562 await AmapLocation.instance.updatePrivacyAgree(true);
389 - final poiList = await AmapSearch.instance.searchKeyword(  
390 - text,  
391 - city: "",  
392 - );  
393 563
394 - list.clear();  
395 - list.add(poiModel); 564 + await AmapLocation.instance.updatePrivacyShow(true);
  565 + await AmapLocation.instance.updatePrivacyAgree(true);
  566 + if (page == 1) {
  567 + ReGeocode reGeocodeList = await AmapSearch.instance.searchReGeocode(
  568 + latLng,
  569 + );
  570 + // print(await reGeocodeList.toFutureString());
  571 + address = reGeocodeList.formatAddress;
  572 + poiModel = new PoiModel("当前位置", address, latLng);
  573 + list.clear();
  574 + list.add(poiModel);
  575 + }
  576 + final poiList =
  577 + await AmapSearch.instance.searchAround(latLng, city: "", page: page);
  578 +
396 for (var poi in poiList) { 579 for (var poi in poiList) {
397 String? title = await poi.title; 580 String? title = await poi.title;
398 - LatLng? latLng = await poi.latLng;  
399 String? cityName = await poi.cityName; 581 String? cityName = await poi.cityName;
400 String? provinceName = await poi.provinceName; 582 String? provinceName = await poi.provinceName;
401 String? address = await poi.address; 583 String? address = await poi.address;
  584 + LatLng? latLng = await poi.latLng;
  585 + String? bussniss = poi.businessArea;
  586 +
402 list.add(new PoiModel( 587 list.add(new PoiModel(
403 title.toString(), 588 title.toString(),
404 - provinceName.toString() + cityName.toString() + address.toString(), 589 + provinceName.toString() +
  590 + cityName.toString() +
  591 + address.toString() +
  592 + bussniss.toString(),
405 latLng)); 593 latLng));
406 } 594 }
  595 +
407 setState(() { 596 setState(() {
408 - isloading = false;  
409 - FocusScope.of(context).requestFocus(FocusNode()); 597 + if (showloading) {
  598 + isloading = false;
  599 + }
410 }); 600 });
411 } 601 }
  602 +
  603 + // void searchPoiId(String text) async {
  604 + // await AmapLocation.instance.updatePrivacyShow(true);
  605 + // await AmapLocation.instance.updatePrivacyAgree(true);
  606 + // Poi? poi = await AmapSearch.instance.searchPoiId(
  607 + // text,
  608 + // );
  609 + // print(poi);
  610 + // }
  611 +
  612 + // void searchAroundAddress(String text) async {
  613 + // await AmapLocation.instance.updatePrivacyShow(true);
  614 + // await AmapLocation.instance.updatePrivacyAgree(true);
  615 + // final poiList = await AmapSearch.instance.searchKeyword(
  616 + // text,
  617 + // city: "",
  618 + // );
  619 + // // final poiList = await AmapSearch.instance.searchAround(
  620 + // // LatLng(latitude, longitude),
  621 + // // city: "",
  622 + // // radius: 100000000000000
  623 +
  624 + // // );
  625 +
  626 + // list.clear();
  627 + // list.add(poiModel);
  628 + // for (var poi in poiList) {
  629 + // String? title = await poi.title;
  630 + // LatLng? latLng = await poi.latLng;
  631 + // String? cityName = await poi.cityName;
  632 + // String? provinceName = await poi.provinceName;
  633 + // String? address = await poi.address;
  634 + // list.add(new PoiModel(
  635 + // title.toString(),
  636 + // provinceName.toString() + cityName.toString() + address.toString(),
  637 + // latLng));
  638 + // }
  639 + // setState(() {
  640 + // isloading = false;
  641 + // FocusScope.of(context).requestFocus(FocusNode());
  642 + // });
  643 + // }
412 } 644 }
413 645
414 class PoiModel { 646 class PoiModel {
@@ -145,10 +145,10 @@ packages: @@ -145,10 +145,10 @@ packages:
145 dependency: "direct main" 145 dependency: "direct main"
146 description: 146 description:
147 name: barcode_scan2 147 name: barcode_scan2
148 - sha256: efbe38629e6df2200e4d60ebe252e8e041cd5ae7b50f194a20f01779ade9d1c3 148 + sha256: "0f3eb7c0a0c80a0f65d3fa88737544fdb6d27127a4fad566e980e626f3fb76e1"
149 url: "https://pub.flutter-io.cn" 149 url: "https://pub.flutter-io.cn"
150 source: hosted 150 source: hosted
151 - version: "4.5.0" 151 + version: "4.5.1"
152 boolean_selector: 152 boolean_selector:
153 dependency: transitive 153 dependency: transitive
154 description: 154 description:
@@ -264,7 +264,7 @@ dependencies: @@ -264,7 +264,7 @@ dependencies:
264 # image_cropper: ^4.0.1 264 # image_cropper: ^4.0.1
265 pin_code_fields: ^8.0.1 265 pin_code_fields: ^8.0.1
266 # 二维码扫描 266 # 二维码扫描
267 - barcode_scan2: ^4.5.0 267 + barcode_scan2: ^4.5.1
268 # 柱形图 268 # 柱形图
269 fl_chart: ^0.71.0 269 fl_chart: ^0.71.0
270 270