| | |
| | | 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/services.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/global.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/search_util.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() { |
| | |
| | | BMFMapOptions mapOptions = BMFMapOptions( |
| | | showMapScaleBar: false, |
| | | mapType: BMFMapType.Standard, |
| | | center: BMFCoordinate(39.917215, 116.380341), |
| | | center: Global.currentPosition != null |
| | | ? Global.currentPosition |
| | | : BMFCoordinate(39.917215, 116.380341), |
| | | mapScaleBarPosition: BMFPoint(0, 200), |
| | | zoomLevel: 12, |
| | | mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 200)); |
| | |
| | | |
| | | TextEditingController? editingController; |
| | | List<BMFPoiInfo>? suggestList; |
| | | List<BMFPoiInfo>? recordList; |
| | | BMFCoordinate? currentPosition; |
| | | |
| | | @override |
| | | void initState() { |
| | | super.initState(); |
| | | editingController = TextEditingController(); |
| | | loadRecord(); |
| | | } |
| | | |
| | | //加载记录页面 |
| | | void loadRecord(){ |
| | | SearchUtil.getRecordList().then((value) { |
| | | setState(() { |
| | | recordList = value; |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | //获取地图视图 |
| | |
| | | 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); |
| | | LocationUtil.startLocation(0, (state, map) { |
| | | if (state == LocationState.success) { |
| | | currentPosition = BMFCoordinate.fromMap(map!); |
| | | _mapController!.setCenterCoordinate(currentPosition!, true); |
| | | } |
| | | }); |
| | | }, |
| | | mapOptions: mapOptions, |
| | |
| | | child: Container( |
| | | color: Colors.white, |
| | | padding: const EdgeInsets.only(left: 20, right: 20), |
| | | child: Column( |
| | | children: [getHistoryItem("融恒盈嘉中心-西门", "重庆市江北区", 0)], |
| | | ), |
| | | child: ListView.builder(itemBuilder: (BuildContext context, int index){ |
| | | return getHistoryItem(recordList![index].name!, recordList![index].address!, recordList![index]); |
| | | },itemCount: recordList==null?0:recordList!.length,) , |
| | | )) |
| | | ], |
| | | ); |
| | | } |
| | | |
| | | |
| | | setSearchKey(String key) { |
| | | editingController!.text = key; |
| | |
| | | baseOffset: key.length, extentOffset: editingController!.text.length); |
| | | startPOISearch(key); |
| | | } |
| | | |
| | | // static const messageChannel = |
| | | // const BasicMessageChannel('POISearch', StandardMessageCodec()); |
| | | // |
| | | // void searchPOI() async { |
| | | // Map value = await messageChannel.send({"method": "searchNearBy"}) as Map; |
| | | // if (value["code"] == 0) { |
| | | // print("返回结果为:$value"); |
| | | // } |
| | | // } |
| | | |
| | | startPOISearch(String key) async { |
| | | setState(() { |
| | |
| | | state = 1; |
| | | }); |
| | | |
| | | print("startPOISearch-$key"); |
| | | BMFPoiNearbySearchOption poiNearbySearchOption = BMFPoiNearbySearchOption( |
| | | keywords: <String>[key], |
| | | location: BMFCoordinate(40.049557, 116.279295), |
| | | isRadiusLimit: false); |
| | | location: currentPosition != null |
| | | ? currentPosition |
| | | : BMFCoordinate(29.674509, 106.517571), |
| | | radius: 10000, |
| | | isRadiusLimit: true); |
| | | |
| | | BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch(); |
| | | nearbySearch.onGetPoiNearbySearchResult( |
| | | callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) { |
| | | print("搜索结果回调:$result"); |
| | | setState(() { |
| | | suggestList = result.poiInfoList; |
| | | }); |
| | |
| | | alignment: Alignment.center, child: Text("暂无数据")); |
| | | } else { |
| | | return getHistoryItem(suggestList![index].name!, |
| | | suggestList![index].address!, index); |
| | | suggestList![index].address!, suggestList![index]); |
| | | } |
| | | }, |
| | | itemCount: suggestList != null ? suggestList!.length : 1, |
| | |
| | | } |
| | | |
| | | //历史记录项目 |
| | | Widget getHistoryItem(String title, String content, int index) { |
| | | Widget getHistoryItem(String title, String content, BMFPoiInfo info,{bool showDistance=false}) { |
| | | return InkWell( |
| | | onTap: () { |
| | | print("点击:$index"); |
| | | SearchUtil.addSearchRecord(info); |
| | | }, |
| | | child: Container( |
| | | height: 67, |