admin
2021-11-10 ef43946e123a2e7d4c616e0dc02c89970b71d900
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
 
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart';
import 'package:locations/ui/mine/advice.dart';
import 'package:locations/ui/mine/permission.dart';
import 'package:locations/ui/mine/settings.dart';
import 'package:locations/ui/mine/share_to_friends.dart';
import 'package:locations/ui/mine/try_functions.dart';
import 'package:locations/ui/widget/button.dart';
import 'package:locations/utils/location_util.dart';
import 'package:locations/utils/map_util.dart';
import 'package:locations/utils/pageutils.dart';
import 'package:locations/utils/ui_constant.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
 
//控件阴影
List<BoxShadow> getViewShadow() {
  return [
    BoxShadow(
      blurRadius: 6.5,
      spreadRadius: 1,
      color: Color(0x4D0E96FF),
    )
  ];
}
 
/********************POI搜索********************/
class LocationSearchPage extends StatefulWidget {
  @override
  _LocationSearchPageState createState() => _LocationSearchPageState();
}
 
class _LocationSearchPageState extends State<LocationSearchPage>
    with SingleTickerProviderStateMixin {
  BMFMapController? _mapController;
  BMFMapOptions mapOptions = BMFMapOptions(
      showMapScaleBar: false,
      mapType: BMFMapType.Standard,
      center: BMFCoordinate(39.917215, 116.380341),
      mapScaleBarPosition: BMFPoint(0, 200),
      zoomLevel: 12,
      mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 200));
 
  //1-搜索页面  2-建议搜索页面 3-结果展示页面
  int state = 1;
 
  TextEditingController? editingController;
  List<BMFPoiInfo>? suggestList;
 
  @override
  void initState() {
    super.initState();
    editingController = TextEditingController();
  }
 
  //获取地图视图
  Widget getMapView() {
    return Container(
      child: BMFMapWidget(
        onBMFMapCreated: (controller) {
          _mapController = controller;
          //启动定位
          LocationUtil.init(0);
          LocationUtil.startLocation((map) {
            double lat = map["latitude"] as double;
            double lng = map["logitude"] as double;
            _mapController!.setCenterCoordinate(BMFCoordinate(lng,lat), true);
          });
        },
        mapOptions: mapOptions,
      ),
    );
  }
 
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: Colors.white,
        body: Stack(children: [
          getMapView(),
          Flex(direction: Axis.vertical, children: [
            //搜索框
            Container(
              margin: const EdgeInsets.fromLTRB(10, 35, 10, 11),
              alignment: Alignment.center,
              padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
              height: 45,
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10),
                  boxShadow: getViewShadow()),
              child: Flex(
                direction: Axis.horizontal,
                children: [
                  InkWell(
                      onTap: () {
                        Navigator.of(context).pop();
                      },
                      child: Image.asset(
                        "assets/images/map/icon_location_back.png",
                        height: 30,
                      )),
                  Container(
                    width: 10,
                  ),
                  Expanded(
                      child: TextField(
                    autofocus: false,
                    controller: editingController,
                    onChanged: (text) {
                      print(text);
                      // setState(() {
                      //   if (text.isNotEmpty)
                      //     state = 2;
                      //   else
                      //     state = 1;
                      // });
                      startPOISearch(text);
                    },
                    decoration: const InputDecoration(
                        focusedBorder: InputBorder.none,
                        border: InputBorder.none,
                        hintText: "地图上找位置",
                        hintStyle:
                            TextStyle(fontSize: 14, color: Color(0xFFC4CDD1))),
                  )),
                  InkWell(
                    child: Container(
                        padding: const EdgeInsets.only(right: 10),
                        child: const Text(
                          "搜索",
                          style: TextStyle(
                              color: ColorConstant.theme, fontSize: 15),
                        )),
                  )
                ],
              ),
            ),
 
            Expanded(child: getContentView())
          ])
        ]));
  }
 
  Widget getContentView() {
    if (state == 1)
      return getNotSearchView();
    else if (state == 2) {
      return getSearchSuggestView();
    } else
      return Container();
  }
 
  Widget getNotSearchView() {
    return Column(
      children: [
        Container(
          padding: const EdgeInsets.only(left: 7, right: 7, bottom: 7, top: 7),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: const BorderRadius.only(
                topRight: Radius.circular(15), topLeft: Radius.circular(15)),
            boxShadow: getViewShadow(),
          ),
          child: Column(mainAxisSize: MainAxisSize.min, children: [
            //分类
            Container(
                padding: const EdgeInsets.only(
                    left: 20, right: 20, bottom: 15, top: 9),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    getSugguestSearchType(
                        "酒店",
                        Image.asset(
                          "assets/images/map/icon_location_search_type_hotel.png",
                          height: 34,
                        ), () {
                      setSearchKey("酒店");
                    }),
                    getSugguestSearchType(
                        "餐馆",
                        Image.asset(
                          "assets/images/map/icon_location_search_type_eat.png",
                          height: 34,
                        ), () {
                      setSearchKey("餐馆");
                    }),
                    getSugguestSearchType(
                        "外卖",
                        Image.asset(
                          "assets/images/map/icon_location_search_type_waimai.png",
                          height: 34,
                        ), () {
                      setSearchKey("外卖");
                    }),
                    getSugguestSearchType(
                        "电影院",
                        Image.asset(
                          "assets/images/map/icon_location_search_type_movie.png",
                          height: 34,
                        ), () {
                      setSearchKey("电影院");
                    }),
                    getSugguestSearchType(
                        "景点",
                        Image.asset(
                          "assets/images/map/icon_location_search_type_sense.png",
                          height: 34,
                        ), () {
                      setSearchKey("景点");
                    }),
                  ],
                )),
            //广告
            Container(
              height: 210,
            ),
          ]),
        ),
        //分隔线
        Container(
          height: 10,
          color: const Color(0xFFF0F0F0),
        ),
        Expanded(
            child: Container(
          color: Colors.white,
          padding: const EdgeInsets.only(left: 20, right: 20),
          child: Column(
            children: [getHistoryItem("融恒盈嘉中心-西门", "重庆市江北区", 0)],
          ),
        ))
      ],
    );
  }
 
  setSearchKey(String key) {
    editingController!.text = key;
    editingController!.selection = TextSelection(
        baseOffset: key.length, extentOffset: editingController!.text.length);
    startPOISearch(key);
  }
 
  startPOISearch(String key) async {
    setState(() {
      suggestList = null;
      if (key.isNotEmpty)
        state = 2;
      else
        state = 1;
    });
 
    print("startPOISearch-$key");
    BMFPoiNearbySearchOption poiNearbySearchOption = BMFPoiNearbySearchOption(
        keywords: <String>[key],
        location: BMFCoordinate(40.049557, 116.279295),
        isRadiusLimit: false);
 
    BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch();
    nearbySearch.onGetPoiNearbySearchResult(
        callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) {
      setState(() {
        suggestList = result.poiInfoList;
      });
    });
    bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption);
 
    // BMFSuggestionSearchOption suggestionSearchOption =
    //     BMFSuggestionSearchOption(keyword: key,cityLimit: false);
    // BMFSuggestionSearch suggestionSearch = BMFSuggestionSearch();
    // suggestionSearch.onGetSuggestSearchResult(callback:
    //     (BMFSuggestionSearchResult result, BMFSearchErrorCode errorCode) {
    //   print("result:$result errorCode:$errorCode");
    //   setState(() {
    //     suggestList = result.suggestionList;
    //   });
    // });
    // bool flag = await suggestionSearch.suggestionSearch(suggestionSearchOption);
 
    print("结束$flag");
  }
 
  //建议搜索视图
  Widget getSearchSuggestView() {
    return Container(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15), topRight: Radius.circular(15)),
            boxShadow: getViewShadow()),
        padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
        child: ListView.builder(
          itemBuilder: (BuildContext context, int index) {
            if (suggestList == null) {
              return Container(
                  margin: EdgeInsets.only(top: 50),
                  alignment: Alignment.center,
                  height: 50,
                  width: 50,
                  child: CircularProgressIndicator(strokeWidth: 3.0));
            } else if (suggestList!.length == 0) {
              return Container(
                  alignment: Alignment.center, child: Text("暂无数据"));
            } else {
              return getHistoryItem(suggestList![index].name!,
                  suggestList![index].address!, index);
            }
          },
          itemCount: suggestList != null ? suggestList!.length : 1,
          padding: const EdgeInsets.all(0),
        ));
  }
 
  //历史记录项目
  Widget getHistoryItem(String title, String content, int index) {
    return InkWell(
        onTap: () {
          print("点击:$index");
        },
        child: Container(
          height: 67,
          decoration: BoxDecoration(
              color: Colors.white,
              border: const Border(
                  bottom: BorderSide(
                      // 设置单侧边框的样式
                      color: Color(0xFFF1F2F3),
                      width: 1,
                      style: BorderStyle.solid))),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                  padding: EdgeInsets.only(top: 12, right: 9),
                  alignment: Alignment.topCenter,
                  child: Image.asset(
                    "assets/images/map/icon_location_location.png",
                    height: 16,
                  )),
              Expanded(
                  child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    title,
                    softWrap: false,
                    overflow: TextOverflow.ellipsis,
                    style:
                        const TextStyle(color: Color(0xFF333333), fontSize: 13),
                  ),
                  Container(
                    height: 5,
                  ),
                  Text(
                    content,
                    style:
                        const TextStyle(color: Color(0xFF9DAAB3), fontSize: 11),
                  ),
                ],
              )),
              Image.asset(
                "assets/images/map/icon_location_position_input.png",
                height: 20,
              )
            ],
          ),
        ));
  }
 
  Widget getSugguestSearchType(
      String title, Image icon, GestureTapCallback _onClick) {
    return InkWell(
        onTap: () {
          _onClick();
        },
        child: Flex(
          direction: Axis.vertical,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            icon,
            Container(
              height: 5,
            ),
            Text(
              title,
              style: const TextStyle(color: Color(0xFF333333), fontSize: 11),
            )
          ],
        ));
  }
}
 
/********************位置详情********************/
class PositionDetailPage extends StatefulWidget {
  @override
  _PositionDetailPageState createState() => _PositionDetailPageState();
}
 
class _PositionDetailPageState extends State<PositionDetailPage>
    with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}