diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 08a230f..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,11 @@ import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/pages/demo/mapPage/create_map_page.dart'; import 'package:base_app/ui/pages/main_left_page.dart'; import 'package:base_app/ui/widgets/common/button/large_button_widget.dart'; import 'package:base_app/utils/util_index.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'mapPage/draw_map_page.dart'; +import 'mapPage/tianditu_map_page.dart'; /// 简洁主页面 class MapPage extends StatelessWidget { @@ -16,25 +15,19 @@ @override Widget build(BuildContext context) { - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', + // 天地图实验 + Widget tiandituMap = new LargeButton( + text: '天地图', iconPath: "", onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); + NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 08a230f..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,11 @@ import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/pages/demo/mapPage/create_map_page.dart'; import 'package:base_app/ui/pages/main_left_page.dart'; import 'package:base_app/ui/widgets/common/button/large_button_widget.dart'; import 'package:base_app/utils/util_index.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'mapPage/draw_map_page.dart'; +import 'mapPage/tianditu_map_page.dart'; /// 简洁主页面 class MapPage extends StatelessWidget { @@ -16,25 +15,19 @@ @override Widget build(BuildContext context) { - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', + // 天地图实验 + Widget tiandituMap = new LargeButton( + text: '天地图', iconPath: "", onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); + NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } diff --git a/lib/ui/widgets/map/zoom_plugin.dart b/lib/ui/widgets/map/zoom_plugin.dart new file mode 100644 index 0000000..9f27b70 --- /dev/null +++ b/lib/ui/widgets/map/zoom_plugin.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:flutter_map/plugin_api.dart'; + +class ZoomButtonsPluginOption extends LayerOptions { + final int minZoom; + final int maxZoom; + final bool mini; + final double padding; + final Alignment alignment; + final Color zoomInColor; + final Color zoomInColorIcon; + final Color zoomOutColor; + final Color zoomOutColorIcon; + final IconData zoomInIcon; + final IconData zoomOutIcon; + + ZoomButtonsPluginOption({ + Key key, + this.minZoom = 1, + this.maxZoom = 18, + this.mini = true, + this.padding = 2.0, + this.alignment = Alignment.topRight, + this.zoomInColor, + this.zoomInColorIcon, + this.zoomInIcon = Icons.zoom_in, + this.zoomOutColor, + this.zoomOutColorIcon, + this.zoomOutIcon = Icons.zoom_out, + Stream rebuild, + }) : super(key: key, rebuild: rebuild); +} + +class ZoomButtonsPlugin implements MapPlugin { + @override + Widget createLayer( + LayerOptions options, MapState mapState, Stream stream) { + if (options is ZoomButtonsPluginOption) { + return ZoomButtons(options, mapState, stream); + } + throw Exception('Unknown options type for ZoomButtonsPlugin: $options'); + } + + @override + bool supportsLayer(LayerOptions options) { + return options is ZoomButtonsPluginOption; + } +} + +class ZoomButtons extends StatelessWidget { + final ZoomButtonsPluginOption zoomButtonsOpts; + final MapState map; + final Stream stream; + final FitBoundsOptions options = + const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) + : super(key: zoomButtonsOpts.key); + + @override + Widget build(BuildContext context) { + return Align( + alignment: zoomButtonsOpts.alignment, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: zoomButtonsOpts.padding, + top: zoomButtonsOpts.padding, + right: zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomInButton', + mini: zoomButtonsOpts.mini, + backgroundColor: + zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom + 1; + if (zoom < zoomButtonsOpts.minZoom) { + zoom = zoomButtonsOpts.minZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomInIcon, + color: zoomButtonsOpts.zoomInColorIcon ?? + IconTheme.of(context).color), + ), + ), + Padding( + padding: EdgeInsets.all(zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomOutButton', + mini: zoomButtonsOpts.mini, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? + Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom - 1; + if (zoom > zoomButtonsOpts.maxZoom) { + zoom = zoomButtonsOpts.maxZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomOutIcon, + color: zoomButtonsOpts.zoomOutColorIcon ?? + IconTheme.of(context).color), + ), + ), + ], + ), + ); + } +} diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 08a230f..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,11 @@ import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/pages/demo/mapPage/create_map_page.dart'; import 'package:base_app/ui/pages/main_left_page.dart'; import 'package:base_app/ui/widgets/common/button/large_button_widget.dart'; import 'package:base_app/utils/util_index.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'mapPage/draw_map_page.dart'; +import 'mapPage/tianditu_map_page.dart'; /// 简洁主页面 class MapPage extends StatelessWidget { @@ -16,25 +15,19 @@ @override Widget build(BuildContext context) { - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', + // 天地图实验 + Widget tiandituMap = new LargeButton( + text: '天地图', iconPath: "", onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); + NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } diff --git a/lib/ui/widgets/map/zoom_plugin.dart b/lib/ui/widgets/map/zoom_plugin.dart new file mode 100644 index 0000000..9f27b70 --- /dev/null +++ b/lib/ui/widgets/map/zoom_plugin.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:flutter_map/plugin_api.dart'; + +class ZoomButtonsPluginOption extends LayerOptions { + final int minZoom; + final int maxZoom; + final bool mini; + final double padding; + final Alignment alignment; + final Color zoomInColor; + final Color zoomInColorIcon; + final Color zoomOutColor; + final Color zoomOutColorIcon; + final IconData zoomInIcon; + final IconData zoomOutIcon; + + ZoomButtonsPluginOption({ + Key key, + this.minZoom = 1, + this.maxZoom = 18, + this.mini = true, + this.padding = 2.0, + this.alignment = Alignment.topRight, + this.zoomInColor, + this.zoomInColorIcon, + this.zoomInIcon = Icons.zoom_in, + this.zoomOutColor, + this.zoomOutColorIcon, + this.zoomOutIcon = Icons.zoom_out, + Stream rebuild, + }) : super(key: key, rebuild: rebuild); +} + +class ZoomButtonsPlugin implements MapPlugin { + @override + Widget createLayer( + LayerOptions options, MapState mapState, Stream stream) { + if (options is ZoomButtonsPluginOption) { + return ZoomButtons(options, mapState, stream); + } + throw Exception('Unknown options type for ZoomButtonsPlugin: $options'); + } + + @override + bool supportsLayer(LayerOptions options) { + return options is ZoomButtonsPluginOption; + } +} + +class ZoomButtons extends StatelessWidget { + final ZoomButtonsPluginOption zoomButtonsOpts; + final MapState map; + final Stream stream; + final FitBoundsOptions options = + const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) + : super(key: zoomButtonsOpts.key); + + @override + Widget build(BuildContext context) { + return Align( + alignment: zoomButtonsOpts.alignment, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: zoomButtonsOpts.padding, + top: zoomButtonsOpts.padding, + right: zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomInButton', + mini: zoomButtonsOpts.mini, + backgroundColor: + zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom + 1; + if (zoom < zoomButtonsOpts.minZoom) { + zoom = zoomButtonsOpts.minZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomInIcon, + color: zoomButtonsOpts.zoomInColorIcon ?? + IconTheme.of(context).color), + ), + ), + Padding( + padding: EdgeInsets.all(zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomOutButton', + mini: zoomButtonsOpts.mini, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? + Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom - 1; + if (zoom > zoomButtonsOpts.maxZoom) { + zoom = zoomButtonsOpts.maxZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomOutIcon, + color: zoomButtonsOpts.zoomOutColorIcon ?? + IconTheme.of(context).color), + ), + ), + ], + ), + ); + } +} diff --git a/lib/utils/map_utils.dart b/lib/utils/map_utils.dart deleted file mode 100644 index dc6029d..0000000 --- a/lib/utils/map_utils.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:math'; - -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; - -/// 地图工具类 -class MapUtils { - ///计算两点距离 - ///[start] 第一个点坐标[lng,lat] - ///[end]第二个点坐标[lng,lat] - static double calculateDistance(start, end) { - if ((start != null) || (end != null)) { - double d1 = 0.01745329251994329; - double d2 = start[0]; //lng - double d3 = start[1]; //lat - double d4 = end[0]; //lng - double d5 = end[1]; //lat - d2 *= d1; - d3 *= d1; - d4 *= d1; - d5 *= d1; - double d6 = sin(d2); - double d7 = sin(d3); - double d8 = cos(d2); - double d9 = cos(d3); - double d10 = sin(d4); - double d11 = sin(d5); - double d12 = cos(d4); - double d13 = cos(d5); - List arrayOfDouble1 = List(3); - List arrayOfDouble2 = List(3); - arrayOfDouble1[0] = (d9 * d8); - arrayOfDouble1[1] = (d9 * d6); - arrayOfDouble1[2] = d7; - arrayOfDouble2[0] = (d13 * d12); - arrayOfDouble2[1] = (d13 * d10); - arrayOfDouble2[2] = d11; - double d14 = sqrt((arrayOfDouble1[0] - arrayOfDouble2[0]) * - (arrayOfDouble1[0] - arrayOfDouble2[0]) + - (arrayOfDouble1[1] - arrayOfDouble2[1]) * - (arrayOfDouble1[1] - arrayOfDouble2[1]) + - (arrayOfDouble1[2] - arrayOfDouble2[2]) * - (arrayOfDouble1[2] - arrayOfDouble2[2])); - print((asin(d14 / 2.0) * 12742001.579854401)); - return (asin(d14 / 2.0) * 12742001.579854401).abs(); - } else { - return 0.0; - } - } -} - -/// 获取随机坐标 -mixin NextLatLng { - final random = Random(); - - LatLng getNextLatLng({LatLng center}) { - center ??= LatLng(39.90960, 116.397228); - return LatLng( - center.latitude + random.nextDouble(), - center.longitude + random.nextDouble(), - ); - } - - List getNextBatchLatLng(int count) { - return [ - for (int i = 0; i < count; i++) - LatLng( - 39.90960 + random.nextDouble() * 4, - 116.397228 + random.nextDouble() * 4, - ) - ]; - } -} diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 08a230f..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,11 @@ import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/pages/demo/mapPage/create_map_page.dart'; import 'package:base_app/ui/pages/main_left_page.dart'; import 'package:base_app/ui/widgets/common/button/large_button_widget.dart'; import 'package:base_app/utils/util_index.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'mapPage/draw_map_page.dart'; +import 'mapPage/tianditu_map_page.dart'; /// 简洁主页面 class MapPage extends StatelessWidget { @@ -16,25 +15,19 @@ @override Widget build(BuildContext context) { - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', + // 天地图实验 + Widget tiandituMap = new LargeButton( + text: '天地图', iconPath: "", onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); + NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } diff --git a/lib/ui/widgets/map/zoom_plugin.dart b/lib/ui/widgets/map/zoom_plugin.dart new file mode 100644 index 0000000..9f27b70 --- /dev/null +++ b/lib/ui/widgets/map/zoom_plugin.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:flutter_map/plugin_api.dart'; + +class ZoomButtonsPluginOption extends LayerOptions { + final int minZoom; + final int maxZoom; + final bool mini; + final double padding; + final Alignment alignment; + final Color zoomInColor; + final Color zoomInColorIcon; + final Color zoomOutColor; + final Color zoomOutColorIcon; + final IconData zoomInIcon; + final IconData zoomOutIcon; + + ZoomButtonsPluginOption({ + Key key, + this.minZoom = 1, + this.maxZoom = 18, + this.mini = true, + this.padding = 2.0, + this.alignment = Alignment.topRight, + this.zoomInColor, + this.zoomInColorIcon, + this.zoomInIcon = Icons.zoom_in, + this.zoomOutColor, + this.zoomOutColorIcon, + this.zoomOutIcon = Icons.zoom_out, + Stream rebuild, + }) : super(key: key, rebuild: rebuild); +} + +class ZoomButtonsPlugin implements MapPlugin { + @override + Widget createLayer( + LayerOptions options, MapState mapState, Stream stream) { + if (options is ZoomButtonsPluginOption) { + return ZoomButtons(options, mapState, stream); + } + throw Exception('Unknown options type for ZoomButtonsPlugin: $options'); + } + + @override + bool supportsLayer(LayerOptions options) { + return options is ZoomButtonsPluginOption; + } +} + +class ZoomButtons extends StatelessWidget { + final ZoomButtonsPluginOption zoomButtonsOpts; + final MapState map; + final Stream stream; + final FitBoundsOptions options = + const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) + : super(key: zoomButtonsOpts.key); + + @override + Widget build(BuildContext context) { + return Align( + alignment: zoomButtonsOpts.alignment, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: zoomButtonsOpts.padding, + top: zoomButtonsOpts.padding, + right: zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomInButton', + mini: zoomButtonsOpts.mini, + backgroundColor: + zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom + 1; + if (zoom < zoomButtonsOpts.minZoom) { + zoom = zoomButtonsOpts.minZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomInIcon, + color: zoomButtonsOpts.zoomInColorIcon ?? + IconTheme.of(context).color), + ), + ), + Padding( + padding: EdgeInsets.all(zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomOutButton', + mini: zoomButtonsOpts.mini, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? + Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom - 1; + if (zoom > zoomButtonsOpts.maxZoom) { + zoom = zoomButtonsOpts.maxZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomOutIcon, + color: zoomButtonsOpts.zoomOutColorIcon ?? + IconTheme.of(context).color), + ), + ), + ], + ), + ); + } +} diff --git a/lib/utils/map_utils.dart b/lib/utils/map_utils.dart deleted file mode 100644 index dc6029d..0000000 --- a/lib/utils/map_utils.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:math'; - -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; - -/// 地图工具类 -class MapUtils { - ///计算两点距离 - ///[start] 第一个点坐标[lng,lat] - ///[end]第二个点坐标[lng,lat] - static double calculateDistance(start, end) { - if ((start != null) || (end != null)) { - double d1 = 0.01745329251994329; - double d2 = start[0]; //lng - double d3 = start[1]; //lat - double d4 = end[0]; //lng - double d5 = end[1]; //lat - d2 *= d1; - d3 *= d1; - d4 *= d1; - d5 *= d1; - double d6 = sin(d2); - double d7 = sin(d3); - double d8 = cos(d2); - double d9 = cos(d3); - double d10 = sin(d4); - double d11 = sin(d5); - double d12 = cos(d4); - double d13 = cos(d5); - List arrayOfDouble1 = List(3); - List arrayOfDouble2 = List(3); - arrayOfDouble1[0] = (d9 * d8); - arrayOfDouble1[1] = (d9 * d6); - arrayOfDouble1[2] = d7; - arrayOfDouble2[0] = (d13 * d12); - arrayOfDouble2[1] = (d13 * d10); - arrayOfDouble2[2] = d11; - double d14 = sqrt((arrayOfDouble1[0] - arrayOfDouble2[0]) * - (arrayOfDouble1[0] - arrayOfDouble2[0]) + - (arrayOfDouble1[1] - arrayOfDouble2[1]) * - (arrayOfDouble1[1] - arrayOfDouble2[1]) + - (arrayOfDouble1[2] - arrayOfDouble2[2]) * - (arrayOfDouble1[2] - arrayOfDouble2[2])); - print((asin(d14 / 2.0) * 12742001.579854401)); - return (asin(d14 / 2.0) * 12742001.579854401).abs(); - } else { - return 0.0; - } - } -} - -/// 获取随机坐标 -mixin NextLatLng { - final random = Random(); - - LatLng getNextLatLng({LatLng center}) { - center ??= LatLng(39.90960, 116.397228); - return LatLng( - center.latitude + random.nextDouble(), - center.longitude + random.nextDouble(), - ); - } - - List getNextBatchLatLng(int count) { - return [ - for (int i = 0; i < count; i++) - LatLng( - 39.90960 + random.nextDouble() * 4, - 116.397228 + random.nextDouble() * 4, - ) - ]; - } -} diff --git a/lib/utils/util_index.dart b/lib/utils/util_index.dart index b240611..e0ea1ac 100644 --- a/lib/utils/util_index.dart +++ b/lib/utils/util_index.dart @@ -2,7 +2,6 @@ export 'login_utils.dart'; export 'http_utils.dart'; export 'encrypt_helper.dart'; -export 'map_utils.dart'; export 'navigator_util.dart'; export 'route_util.dart'; export 'utils.dart'; diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 08a230f..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,11 @@ import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/pages/demo/mapPage/create_map_page.dart'; import 'package:base_app/ui/pages/main_left_page.dart'; import 'package:base_app/ui/widgets/common/button/large_button_widget.dart'; import 'package:base_app/utils/util_index.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'mapPage/draw_map_page.dart'; +import 'mapPage/tianditu_map_page.dart'; /// 简洁主页面 class MapPage extends StatelessWidget { @@ -16,25 +15,19 @@ @override Widget build(BuildContext context) { - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', + // 天地图实验 + Widget tiandituMap = new LargeButton( + text: '天地图', iconPath: "", onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); + NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } diff --git a/lib/ui/widgets/map/zoom_plugin.dart b/lib/ui/widgets/map/zoom_plugin.dart new file mode 100644 index 0000000..9f27b70 --- /dev/null +++ b/lib/ui/widgets/map/zoom_plugin.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:flutter_map/plugin_api.dart'; + +class ZoomButtonsPluginOption extends LayerOptions { + final int minZoom; + final int maxZoom; + final bool mini; + final double padding; + final Alignment alignment; + final Color zoomInColor; + final Color zoomInColorIcon; + final Color zoomOutColor; + final Color zoomOutColorIcon; + final IconData zoomInIcon; + final IconData zoomOutIcon; + + ZoomButtonsPluginOption({ + Key key, + this.minZoom = 1, + this.maxZoom = 18, + this.mini = true, + this.padding = 2.0, + this.alignment = Alignment.topRight, + this.zoomInColor, + this.zoomInColorIcon, + this.zoomInIcon = Icons.zoom_in, + this.zoomOutColor, + this.zoomOutColorIcon, + this.zoomOutIcon = Icons.zoom_out, + Stream rebuild, + }) : super(key: key, rebuild: rebuild); +} + +class ZoomButtonsPlugin implements MapPlugin { + @override + Widget createLayer( + LayerOptions options, MapState mapState, Stream stream) { + if (options is ZoomButtonsPluginOption) { + return ZoomButtons(options, mapState, stream); + } + throw Exception('Unknown options type for ZoomButtonsPlugin: $options'); + } + + @override + bool supportsLayer(LayerOptions options) { + return options is ZoomButtonsPluginOption; + } +} + +class ZoomButtons extends StatelessWidget { + final ZoomButtonsPluginOption zoomButtonsOpts; + final MapState map; + final Stream stream; + final FitBoundsOptions options = + const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) + : super(key: zoomButtonsOpts.key); + + @override + Widget build(BuildContext context) { + return Align( + alignment: zoomButtonsOpts.alignment, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: zoomButtonsOpts.padding, + top: zoomButtonsOpts.padding, + right: zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomInButton', + mini: zoomButtonsOpts.mini, + backgroundColor: + zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom + 1; + if (zoom < zoomButtonsOpts.minZoom) { + zoom = zoomButtonsOpts.minZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomInIcon, + color: zoomButtonsOpts.zoomInColorIcon ?? + IconTheme.of(context).color), + ), + ), + Padding( + padding: EdgeInsets.all(zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomOutButton', + mini: zoomButtonsOpts.mini, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? + Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom - 1; + if (zoom > zoomButtonsOpts.maxZoom) { + zoom = zoomButtonsOpts.maxZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomOutIcon, + color: zoomButtonsOpts.zoomOutColorIcon ?? + IconTheme.of(context).color), + ), + ), + ], + ), + ); + } +} diff --git a/lib/utils/map_utils.dart b/lib/utils/map_utils.dart deleted file mode 100644 index dc6029d..0000000 --- a/lib/utils/map_utils.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:math'; - -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; - -/// 地图工具类 -class MapUtils { - ///计算两点距离 - ///[start] 第一个点坐标[lng,lat] - ///[end]第二个点坐标[lng,lat] - static double calculateDistance(start, end) { - if ((start != null) || (end != null)) { - double d1 = 0.01745329251994329; - double d2 = start[0]; //lng - double d3 = start[1]; //lat - double d4 = end[0]; //lng - double d5 = end[1]; //lat - d2 *= d1; - d3 *= d1; - d4 *= d1; - d5 *= d1; - double d6 = sin(d2); - double d7 = sin(d3); - double d8 = cos(d2); - double d9 = cos(d3); - double d10 = sin(d4); - double d11 = sin(d5); - double d12 = cos(d4); - double d13 = cos(d5); - List arrayOfDouble1 = List(3); - List arrayOfDouble2 = List(3); - arrayOfDouble1[0] = (d9 * d8); - arrayOfDouble1[1] = (d9 * d6); - arrayOfDouble1[2] = d7; - arrayOfDouble2[0] = (d13 * d12); - arrayOfDouble2[1] = (d13 * d10); - arrayOfDouble2[2] = d11; - double d14 = sqrt((arrayOfDouble1[0] - arrayOfDouble2[0]) * - (arrayOfDouble1[0] - arrayOfDouble2[0]) + - (arrayOfDouble1[1] - arrayOfDouble2[1]) * - (arrayOfDouble1[1] - arrayOfDouble2[1]) + - (arrayOfDouble1[2] - arrayOfDouble2[2]) * - (arrayOfDouble1[2] - arrayOfDouble2[2])); - print((asin(d14 / 2.0) * 12742001.579854401)); - return (asin(d14 / 2.0) * 12742001.579854401).abs(); - } else { - return 0.0; - } - } -} - -/// 获取随机坐标 -mixin NextLatLng { - final random = Random(); - - LatLng getNextLatLng({LatLng center}) { - center ??= LatLng(39.90960, 116.397228); - return LatLng( - center.latitude + random.nextDouble(), - center.longitude + random.nextDouble(), - ); - } - - List getNextBatchLatLng(int count) { - return [ - for (int i = 0; i < count; i++) - LatLng( - 39.90960 + random.nextDouble() * 4, - 116.397228 + random.nextDouble() * 4, - ) - ]; - } -} diff --git a/lib/utils/util_index.dart b/lib/utils/util_index.dart index b240611..e0ea1ac 100644 --- a/lib/utils/util_index.dart +++ b/lib/utils/util_index.dart @@ -2,7 +2,6 @@ export 'login_utils.dart'; export 'http_utils.dart'; export 'encrypt_helper.dart'; -export 'map_utils.dart'; export 'navigator_util.dart'; export 'route_util.dart'; export 'utils.dart'; diff --git a/pubspec.lock b/pubspec.lock index 74cac3b..0bcfd8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,27 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - amap_core_fluttify: + ansicolor: dependency: transitive description: - name: amap_core_fluttify + name: ansicolor url: "https://pub.flutter-io.cn" source: hosted - version: "0.9.5" - amap_map_fluttify: - dependency: "direct main" - description: - name: amap_map_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.24.0+3" - archive: - dependency: transitive - description: - name: archive - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.13" + version: "1.1.1" args: dependency: transitive description: @@ -35,14 +21,14 @@ name: asn1lib url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.5" + version: "0.8.1" async: dependency: transitive description: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.1" + version: "2.5.0-nullsafety.1" azlistview: dependency: "direct main" description: @@ -56,7 +42,7 @@ name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.1" cached_network_image: dependency: "direct main" description: @@ -64,34 +50,48 @@ url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.3" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "1.1.0-nullsafety.1" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.14.12" + version: "1.15.0-nullsafety.3" common_utils: dependency: transitive description: name: common_utils url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.1" + version: "1.2.4" + console_log_handler: + dependency: transitive + description: + name: console_log_handler + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.6" convert: dependency: transitive description: @@ -106,20 +106,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.0.8" - core_location_fluttify: - dependency: transitive - description: - name: core_location_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.2.4" crypto: dependency: transitive description: name: crypto url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.4" + version: "2.1.5" cupertino_icons: dependency: "direct main" description: @@ -147,7 +140,21 @@ name: encrypt url: "https://pub.flutter-io.cn" source: hosted - version: "4.0.2" + version: "4.1.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.2.0-nullsafety.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3" file: dependency: transitive description: @@ -188,18 +195,32 @@ url: "https://pub.flutter-io.cn" source: hosted version: "1.1.3" + flutter_image: + dependency: transitive + description: + name: flutter_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.0" flutter_localizations: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_map: + dependency: "direct main" + description: + name: flutter_map + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.11.0" flutter_plugin_android_lifecycle: dependency: transitive description: name: flutter_plugin_android_lifecycle url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.8" + version: "1.0.11" flutter_test: dependency: "direct dev" description: flutter @@ -210,13 +231,6 @@ description: flutter source: sdk version: "0.0.0" - foundation_fluttify: - dependency: transitive - description: - name: foundation_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.8.11" http: dependency: transitive description: @@ -231,27 +245,20 @@ url: "https://pub.flutter-io.cn" source: hosted version: "3.1.4" - image: - dependency: transitive - description: - name: image - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.12" image_picker: dependency: "direct main" description: name: image_picker url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.7+4" + version: "0.6.7+22" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.1.6" install_apk_plugin: dependency: "direct main" description: @@ -266,34 +273,62 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.16.1" - latlng: + latlong: dependency: transitive description: - name: latlng + name: latlong url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.2" + version: "0.6.1" + lists: + dependency: transitive + description: + name: lists + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.6" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.11.4" lpinyin: dependency: "direct main" description: name: lpinyin url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.9" + version: "1.1.1" matcher: dependency: transitive description: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.6" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety.3" + mgrs_dart: + dependency: transitive + description: + name: mgrs_dart + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.9.7" oktoast: dependency: "direct main" description: @@ -307,14 +342,14 @@ name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.4" + version: "1.8.0-nullsafety.1" path_provider: dependency: transitive description: name: path_provider url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.11" + version: "1.6.27" path_provider_linux: dependency: transitive description: @@ -328,42 +363,42 @@ name: path_provider_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.4+3" + version: "0.0.4+8" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+3" pedantic: dependency: transitive description: name: pedantic url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.0" + version: "1.9.2" permission_handler: dependency: "direct main" description: name: permission_handler url: "https://pub.flutter-io.cn" source: hosted - version: "5.0.1+1" + version: "5.1.0+2" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.4.0" + version: "2.0.2" photo_view: dependency: "direct main" description: @@ -378,27 +413,27 @@ url: "https://pub.flutter-io.cn" source: hosted version: "2.2.1" - platform_detect: - dependency: transitive - description: - name: platform_detect - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.4.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "1.0.3" pointycastle: dependency: transitive description: name: pointycastle url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "2.0.1" + positioned_tap_detector: + dependency: transitive + description: + name: positioned_tap_detector + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" process: dependency: transitive description: @@ -406,13 +441,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "3.0.13" - pub_semver: + proj4dart: dependency: transitive description: - name: pub_semver + name: proj4dart url: "https://pub.flutter-io.cn" source: hosted - version: "1.4.4" + version: "1.0.5" pull_to_refresh: dependency: "direct main" description: @@ -426,7 +461,7 @@ name: quiver url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.3" + version: "2.1.5" rational: dependency: transitive description: @@ -447,28 +482,28 @@ name: share url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.4+3" + version: "0.6.5+4" shared_preferences: dependency: transitive description: name: shared_preferences url: "https://pub.flutter-io.cn" source: hosted - version: "0.5.8" + version: "0.5.12+4" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.2+1" + version: "0.0.2+4" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+10" + version: "0.0.1+11" shared_preferences_platform_interface: dependency: transitive description: @@ -483,6 +518,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.1.2+7" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.2+3" sky_engine: dependency: transitive description: flutter @@ -494,49 +536,49 @@ name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.7.0" + version: "1.8.0-nullsafety.2" sp_util: dependency: transitive description: name: sp_util url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "1.0.2" sqflite: dependency: "direct main" description: name: sqflite url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.1" + version: "1.3.2+3" sqflite_common: dependency: transitive description: name: sqflite_common url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2+1" + version: "1.0.3+1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.5" + version: "1.1.0-nullsafety.1" synchronized: dependency: transitive description: @@ -550,91 +592,133 @@ name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.15" + version: "0.2.19-nullsafety.2" + transparent_image: + dependency: transitive + description: + name: transparent_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.0" + tuple: + dependency: transitive + description: + name: tuple + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" typed_data: dependency: transitive description: name: typed_data url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.3" + unicode: + dependency: transitive + description: + name: unicode + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.4" url_launcher: dependency: "direct main" description: name: url_launcher url: "https://pub.flutter-io.cn" source: hosted - version: "5.5.0" + version: "5.7.10" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+1" + version: "0.0.1+4" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+7" + version: "0.0.1+9" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.7" + version: "1.0.9" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.2" + version: "0.1.5+3" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+3" uuid: dependency: transitive description: name: uuid url: "https://pub.flutter-io.cn" source: hosted - version: "2.2.0" + version: "2.2.2" + validate: + dependency: transitive + description: + name: validate + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.3" webview_flutter: dependency: "direct main" description: name: webview_flutter url: "https://pub.flutter-io.cn" source: hosted - version: "0.3.22+1" + version: "0.3.24" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.4+1" + wkt_parser: + dependency: transitive + description: + name: wkt_parser + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.7" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.0" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.flutter-io.cn" - source: hosted - version: "3.6.1" + version: "0.1.2" sdks: - dart: ">=2.8.0 <3.0.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + dart: ">=2.10.2 <2.11.0" + flutter: ">=1.22.2 <2.0.0" diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 08a230f..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,11 @@ import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/pages/demo/mapPage/create_map_page.dart'; import 'package:base_app/ui/pages/main_left_page.dart'; import 'package:base_app/ui/widgets/common/button/large_button_widget.dart'; import 'package:base_app/utils/util_index.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'mapPage/draw_map_page.dart'; +import 'mapPage/tianditu_map_page.dart'; /// 简洁主页面 class MapPage extends StatelessWidget { @@ -16,25 +15,19 @@ @override Widget build(BuildContext context) { - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', + // 天地图实验 + Widget tiandituMap = new LargeButton( + text: '天地图', iconPath: "", onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); + NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } diff --git a/lib/ui/widgets/map/zoom_plugin.dart b/lib/ui/widgets/map/zoom_plugin.dart new file mode 100644 index 0000000..9f27b70 --- /dev/null +++ b/lib/ui/widgets/map/zoom_plugin.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:flutter_map/plugin_api.dart'; + +class ZoomButtonsPluginOption extends LayerOptions { + final int minZoom; + final int maxZoom; + final bool mini; + final double padding; + final Alignment alignment; + final Color zoomInColor; + final Color zoomInColorIcon; + final Color zoomOutColor; + final Color zoomOutColorIcon; + final IconData zoomInIcon; + final IconData zoomOutIcon; + + ZoomButtonsPluginOption({ + Key key, + this.minZoom = 1, + this.maxZoom = 18, + this.mini = true, + this.padding = 2.0, + this.alignment = Alignment.topRight, + this.zoomInColor, + this.zoomInColorIcon, + this.zoomInIcon = Icons.zoom_in, + this.zoomOutColor, + this.zoomOutColorIcon, + this.zoomOutIcon = Icons.zoom_out, + Stream rebuild, + }) : super(key: key, rebuild: rebuild); +} + +class ZoomButtonsPlugin implements MapPlugin { + @override + Widget createLayer( + LayerOptions options, MapState mapState, Stream stream) { + if (options is ZoomButtonsPluginOption) { + return ZoomButtons(options, mapState, stream); + } + throw Exception('Unknown options type for ZoomButtonsPlugin: $options'); + } + + @override + bool supportsLayer(LayerOptions options) { + return options is ZoomButtonsPluginOption; + } +} + +class ZoomButtons extends StatelessWidget { + final ZoomButtonsPluginOption zoomButtonsOpts; + final MapState map; + final Stream stream; + final FitBoundsOptions options = + const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) + : super(key: zoomButtonsOpts.key); + + @override + Widget build(BuildContext context) { + return Align( + alignment: zoomButtonsOpts.alignment, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: zoomButtonsOpts.padding, + top: zoomButtonsOpts.padding, + right: zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomInButton', + mini: zoomButtonsOpts.mini, + backgroundColor: + zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom + 1; + if (zoom < zoomButtonsOpts.minZoom) { + zoom = zoomButtonsOpts.minZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomInIcon, + color: zoomButtonsOpts.zoomInColorIcon ?? + IconTheme.of(context).color), + ), + ), + Padding( + padding: EdgeInsets.all(zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomOutButton', + mini: zoomButtonsOpts.mini, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? + Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom - 1; + if (zoom > zoomButtonsOpts.maxZoom) { + zoom = zoomButtonsOpts.maxZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomOutIcon, + color: zoomButtonsOpts.zoomOutColorIcon ?? + IconTheme.of(context).color), + ), + ), + ], + ), + ); + } +} diff --git a/lib/utils/map_utils.dart b/lib/utils/map_utils.dart deleted file mode 100644 index dc6029d..0000000 --- a/lib/utils/map_utils.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:math'; - -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; - -/// 地图工具类 -class MapUtils { - ///计算两点距离 - ///[start] 第一个点坐标[lng,lat] - ///[end]第二个点坐标[lng,lat] - static double calculateDistance(start, end) { - if ((start != null) || (end != null)) { - double d1 = 0.01745329251994329; - double d2 = start[0]; //lng - double d3 = start[1]; //lat - double d4 = end[0]; //lng - double d5 = end[1]; //lat - d2 *= d1; - d3 *= d1; - d4 *= d1; - d5 *= d1; - double d6 = sin(d2); - double d7 = sin(d3); - double d8 = cos(d2); - double d9 = cos(d3); - double d10 = sin(d4); - double d11 = sin(d5); - double d12 = cos(d4); - double d13 = cos(d5); - List arrayOfDouble1 = List(3); - List arrayOfDouble2 = List(3); - arrayOfDouble1[0] = (d9 * d8); - arrayOfDouble1[1] = (d9 * d6); - arrayOfDouble1[2] = d7; - arrayOfDouble2[0] = (d13 * d12); - arrayOfDouble2[1] = (d13 * d10); - arrayOfDouble2[2] = d11; - double d14 = sqrt((arrayOfDouble1[0] - arrayOfDouble2[0]) * - (arrayOfDouble1[0] - arrayOfDouble2[0]) + - (arrayOfDouble1[1] - arrayOfDouble2[1]) * - (arrayOfDouble1[1] - arrayOfDouble2[1]) + - (arrayOfDouble1[2] - arrayOfDouble2[2]) * - (arrayOfDouble1[2] - arrayOfDouble2[2])); - print((asin(d14 / 2.0) * 12742001.579854401)); - return (asin(d14 / 2.0) * 12742001.579854401).abs(); - } else { - return 0.0; - } - } -} - -/// 获取随机坐标 -mixin NextLatLng { - final random = Random(); - - LatLng getNextLatLng({LatLng center}) { - center ??= LatLng(39.90960, 116.397228); - return LatLng( - center.latitude + random.nextDouble(), - center.longitude + random.nextDouble(), - ); - } - - List getNextBatchLatLng(int count) { - return [ - for (int i = 0; i < count; i++) - LatLng( - 39.90960 + random.nextDouble() * 4, - 116.397228 + random.nextDouble() * 4, - ) - ]; - } -} diff --git a/lib/utils/util_index.dart b/lib/utils/util_index.dart index b240611..e0ea1ac 100644 --- a/lib/utils/util_index.dart +++ b/lib/utils/util_index.dart @@ -2,7 +2,6 @@ export 'login_utils.dart'; export 'http_utils.dart'; export 'encrypt_helper.dart'; -export 'map_utils.dart'; export 'navigator_util.dart'; export 'route_util.dart'; export 'utils.dart'; diff --git a/pubspec.lock b/pubspec.lock index 74cac3b..0bcfd8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,27 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - amap_core_fluttify: + ansicolor: dependency: transitive description: - name: amap_core_fluttify + name: ansicolor url: "https://pub.flutter-io.cn" source: hosted - version: "0.9.5" - amap_map_fluttify: - dependency: "direct main" - description: - name: amap_map_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.24.0+3" - archive: - dependency: transitive - description: - name: archive - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.13" + version: "1.1.1" args: dependency: transitive description: @@ -35,14 +21,14 @@ name: asn1lib url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.5" + version: "0.8.1" async: dependency: transitive description: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.1" + version: "2.5.0-nullsafety.1" azlistview: dependency: "direct main" description: @@ -56,7 +42,7 @@ name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.1" cached_network_image: dependency: "direct main" description: @@ -64,34 +50,48 @@ url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.3" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "1.1.0-nullsafety.1" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.14.12" + version: "1.15.0-nullsafety.3" common_utils: dependency: transitive description: name: common_utils url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.1" + version: "1.2.4" + console_log_handler: + dependency: transitive + description: + name: console_log_handler + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.6" convert: dependency: transitive description: @@ -106,20 +106,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.0.8" - core_location_fluttify: - dependency: transitive - description: - name: core_location_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.2.4" crypto: dependency: transitive description: name: crypto url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.4" + version: "2.1.5" cupertino_icons: dependency: "direct main" description: @@ -147,7 +140,21 @@ name: encrypt url: "https://pub.flutter-io.cn" source: hosted - version: "4.0.2" + version: "4.1.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.2.0-nullsafety.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3" file: dependency: transitive description: @@ -188,18 +195,32 @@ url: "https://pub.flutter-io.cn" source: hosted version: "1.1.3" + flutter_image: + dependency: transitive + description: + name: flutter_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.0" flutter_localizations: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_map: + dependency: "direct main" + description: + name: flutter_map + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.11.0" flutter_plugin_android_lifecycle: dependency: transitive description: name: flutter_plugin_android_lifecycle url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.8" + version: "1.0.11" flutter_test: dependency: "direct dev" description: flutter @@ -210,13 +231,6 @@ description: flutter source: sdk version: "0.0.0" - foundation_fluttify: - dependency: transitive - description: - name: foundation_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.8.11" http: dependency: transitive description: @@ -231,27 +245,20 @@ url: "https://pub.flutter-io.cn" source: hosted version: "3.1.4" - image: - dependency: transitive - description: - name: image - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.12" image_picker: dependency: "direct main" description: name: image_picker url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.7+4" + version: "0.6.7+22" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.1.6" install_apk_plugin: dependency: "direct main" description: @@ -266,34 +273,62 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.16.1" - latlng: + latlong: dependency: transitive description: - name: latlng + name: latlong url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.2" + version: "0.6.1" + lists: + dependency: transitive + description: + name: lists + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.6" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.11.4" lpinyin: dependency: "direct main" description: name: lpinyin url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.9" + version: "1.1.1" matcher: dependency: transitive description: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.6" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety.3" + mgrs_dart: + dependency: transitive + description: + name: mgrs_dart + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.9.7" oktoast: dependency: "direct main" description: @@ -307,14 +342,14 @@ name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.4" + version: "1.8.0-nullsafety.1" path_provider: dependency: transitive description: name: path_provider url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.11" + version: "1.6.27" path_provider_linux: dependency: transitive description: @@ -328,42 +363,42 @@ name: path_provider_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.4+3" + version: "0.0.4+8" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+3" pedantic: dependency: transitive description: name: pedantic url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.0" + version: "1.9.2" permission_handler: dependency: "direct main" description: name: permission_handler url: "https://pub.flutter-io.cn" source: hosted - version: "5.0.1+1" + version: "5.1.0+2" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.4.0" + version: "2.0.2" photo_view: dependency: "direct main" description: @@ -378,27 +413,27 @@ url: "https://pub.flutter-io.cn" source: hosted version: "2.2.1" - platform_detect: - dependency: transitive - description: - name: platform_detect - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.4.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "1.0.3" pointycastle: dependency: transitive description: name: pointycastle url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "2.0.1" + positioned_tap_detector: + dependency: transitive + description: + name: positioned_tap_detector + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" process: dependency: transitive description: @@ -406,13 +441,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "3.0.13" - pub_semver: + proj4dart: dependency: transitive description: - name: pub_semver + name: proj4dart url: "https://pub.flutter-io.cn" source: hosted - version: "1.4.4" + version: "1.0.5" pull_to_refresh: dependency: "direct main" description: @@ -426,7 +461,7 @@ name: quiver url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.3" + version: "2.1.5" rational: dependency: transitive description: @@ -447,28 +482,28 @@ name: share url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.4+3" + version: "0.6.5+4" shared_preferences: dependency: transitive description: name: shared_preferences url: "https://pub.flutter-io.cn" source: hosted - version: "0.5.8" + version: "0.5.12+4" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.2+1" + version: "0.0.2+4" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+10" + version: "0.0.1+11" shared_preferences_platform_interface: dependency: transitive description: @@ -483,6 +518,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.1.2+7" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.2+3" sky_engine: dependency: transitive description: flutter @@ -494,49 +536,49 @@ name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.7.0" + version: "1.8.0-nullsafety.2" sp_util: dependency: transitive description: name: sp_util url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "1.0.2" sqflite: dependency: "direct main" description: name: sqflite url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.1" + version: "1.3.2+3" sqflite_common: dependency: transitive description: name: sqflite_common url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2+1" + version: "1.0.3+1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.5" + version: "1.1.0-nullsafety.1" synchronized: dependency: transitive description: @@ -550,91 +592,133 @@ name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.15" + version: "0.2.19-nullsafety.2" + transparent_image: + dependency: transitive + description: + name: transparent_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.0" + tuple: + dependency: transitive + description: + name: tuple + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" typed_data: dependency: transitive description: name: typed_data url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.3" + unicode: + dependency: transitive + description: + name: unicode + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.4" url_launcher: dependency: "direct main" description: name: url_launcher url: "https://pub.flutter-io.cn" source: hosted - version: "5.5.0" + version: "5.7.10" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+1" + version: "0.0.1+4" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+7" + version: "0.0.1+9" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.7" + version: "1.0.9" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.2" + version: "0.1.5+3" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+3" uuid: dependency: transitive description: name: uuid url: "https://pub.flutter-io.cn" source: hosted - version: "2.2.0" + version: "2.2.2" + validate: + dependency: transitive + description: + name: validate + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.3" webview_flutter: dependency: "direct main" description: name: webview_flutter url: "https://pub.flutter-io.cn" source: hosted - version: "0.3.22+1" + version: "0.3.24" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.4+1" + wkt_parser: + dependency: transitive + description: + name: wkt_parser + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.7" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.0" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.flutter-io.cn" - source: hosted - version: "3.6.1" + version: "0.1.2" sdks: - dart: ">=2.8.0 <3.0.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + dart: ">=2.10.2 <2.11.0" + flutter: ">=1.22.2 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 5875161..7d3de0b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,8 +65,10 @@ pull_to_refresh: 1.1.6 # 权限请求插件 permission_handler: ^5.0.0+hotfix.6 - # 高德地图 - amap_map_fluttify: ^0.24.0+3 + # flutter map 基于leaflet的地图包 + flutter_map: ^0.11.0 + #获取定位包 + # location: ^3.2.4 diff --git a/lib/data/net/dio_util.dart b/lib/data/net/dio_util.dart index 837affa..fdfab40 100644 --- a/lib/data/net/dio_util.dart +++ b/lib/data/net/dio_util.dart @@ -5,7 +5,7 @@ import 'package:base_app/common/global.dart'; import 'package:base_app/data/protocol/base_resp.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide Router; /// 请求方法. class Method { @@ -115,6 +115,7 @@ _headers["Cookie"] = cookie; _dio.options.headers.addAll(_headers); } + void setToken(String token) { Map _headers = new Map(); _headers["token"] = token; @@ -163,7 +164,7 @@ /// 返回 status code msg data . Future> request(String method, String path, {data, Options options, CancelToken cancelToken}) async { - // if(options==null){options = _dio.options;} + // if(options==null){options = _dio.options;} Response response = await _dio.request(path, data: data, options: _checkOptions(method, options), @@ -195,8 +196,9 @@ _msg = _dataMap[_msgKey]; _data = _dataMap[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseResp(_status, _code, _msg, _data); } catch (e) { @@ -248,8 +250,9 @@ _msg = _dataMap[_msgKey]; _data = response.data[_dataKey]; } - if(_code==401){ - Router.navigatorKey.currentState.pushNamedAndRemoveUntil(BaseConstant.routeLogin, ModalRoute.withName("/")); + if (_code == 401) { + Router.navigatorKey.currentState.pushNamedAndRemoveUntil( + BaseConstant.routeLogin, ModalRoute.withName("/")); } return new BaseRespR(_status, _code, _msg, _data, response); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index 9be03b8..2f95d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:base_app/res/index.dart'; import 'package:base_app/ui/pages/main_page.dart'; import 'package:base_app/ui/pages/splash_page.dart'; @@ -27,12 +26,6 @@ child: BlocProvider(child: MyApp(), bloc: MainBloc()), )); }); - // 高德地图配置 - await enableFluttifyLog(false); - await AmapService.init( - iosKey: ' 8fcba5276758c8e0b25c5f263c481db2', - androidKey: 'af843eb87ac0e88dac6c08147579ae0e', - ); } /// MyApp核心入口界面 diff --git a/lib/ui/pages/demo/mapPage/create_map_page.dart b/lib/ui/pages/demo/mapPage/create_map_page.dart deleted file mode 100644 index a7bc528..0000000 --- a/lib/ui/pages/demo/mapPage/create_map_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon = AssetImage('assets/images/qidian.png'); - -class CreateMapPage extends StatefulWidget { - @override - _CreateMapPageState createState() => _CreateMapPageState(); -} - -class _CreateMapPageState extends State { - AmapController _controller; // 地图controller - bool showTraffic = false; - Map mapTypeList = { - 'satellite': MapType.Satellite, - 'standard': MapType.Standard, - 'navi': MapType.Navi, - 'bus': MapType.Bus, - 'night': MapType.Night - }; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('自定义地图')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 显示/隐藏路况信息 ", - radius: 8, - onPressed: () { - showTraffic = !showTraffic; - _controller?.showTraffic(showTraffic); - }, - ), - new RoundButton( - text: " 卫星 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['satellite']); - }, - ), - new RoundButton( - text: " 矢量 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['standard']); - }, - ), - new RoundButton( - text: " 公交 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['bus']); - }, - ), - new RoundButton( - text: " 暗黑 ", - radius: 8, - onPressed: () { - _controller.setMapType(mapTypeList['night']); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/draw_map_page.dart b/lib/ui/pages/demo/mapPage/draw_map_page.dart deleted file mode 100644 index efe89a2..0000000 --- a/lib/ui/pages/demo/mapPage/draw_map_page.dart +++ /dev/null @@ -1,213 +0,0 @@ -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; -import 'package:base_app/utils/permission_util.dart'; -import 'package:base_app/utils/util_index.dart'; -import 'package:flutter/material.dart'; -import 'package:oktoast/oktoast.dart'; - -final _assetsIcon1 = AssetImage('assets/images/qidian.png'); - -class DrawMapPage extends StatefulWidget { - @override - _DrawMapPageState createState() => _DrawMapPageState(); -} - -class _DrawMapPageState extends State with NextLatLng { - AmapController _controller; // 地图controller - List _markers = []; // markers - List _circleList = []; //circleList - List _polygonList = []; - Polyline _currentPolyline; - List _pointList = []; - - @override - Widget build(BuildContext context) { - // 功能栏Widget - Widget functionBar = Container( - child: new Column( - children: [ - new FloatingActionButton( - // 回到当前位置按钮 - mini: true, - heroTag: 'gps_setting', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), - onPressed: () async { - final latLng = await _controller?.getLocation(); - final lat = latLng.latitude; - final lng = latLng.longitude; - showToast("$lng,$lat"); - _controller.setCenterCoordinate(latLng); - }), - new FloatingActionButton( - // 清屏 - mini: true, - heroTag: 'refreshData', - shape: new CircleBorder(), - backgroundColor: Colors.white, - child: Icon(Icons.delete, size: 26, color: Colours.gray_66), - onPressed: () async { - await _controller.clearMarkers(_markers); - if (_circleList.isNotEmpty) { - await _circleList.first.remove(); - _circleList.removeAt(0); - } - if (_polygonList.isNotEmpty) { - await _polygonList.first.remove(); - _polygonList.removeAt(0); - } - _currentPolyline?.remove(); - }), - ], - )); - return Scaffold( - appBar: AppBar(title: const Text('地图绘制示例')), - body: new Stack(children: [ - Container( - height: double.infinity, - width: double.infinity, - color: Colors.white24, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Container( - child: AmapView( - showScaleControl: false, // 是否显示比例尺 - showZoomControl: false, // 是否显示缩放控件 - rotateGestureEnabled: false, // 是否允许旋转 - tiltGestureEnabled: false, - onMapCreated: (controller) async { - print("onMapCreate"); - if (await reqPositionPermission()) { - // await controller.showMyLocation(MyLocationOption(show: true)); - _controller = controller; - await _controller?.showMyLocation(MyLocationOption( - myLocationType: MyLocationType.Locate, // 定位模式 - interval: Duration(seconds: 3) // 定位间隔时间 - )); - } - }, - ), - ), - ), - Container( - height: 55.0, - margin: EdgeInsets.all(10), - width: double.infinity, - color: Colors.white, - padding: EdgeInsets.symmetric(horizontal: 8), - child: new Row( - children: [ - new RoundButton( - text: " 绘制点 ", - radius: 8, - onPressed: () async { - final marker = await _controller?.addMarker( - MarkerOption( - latLng: getNextLatLng(), - title: '北京${random.nextDouble()}', - snippet: '描述${random.nextDouble()}', - iconProvider: _assetsIcon1, - infoWindowEnabled: true, - object: '自定义数据${random.nextDouble()}', - ), - ); - // 自定义弹窗 - await _controller - ?.setMarkerClickedListener((marker) async { - await _controller.showCustomInfoWindow( - marker, - Container( - width: 128, - height: 122, - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - ), - child: Text(await marker.title), - ), - ); - }); - _markers.add(marker); - }, - ), - new RoundButton( - text: " 绘制圆 ", - margin: EdgeInsets.symmetric(horizontal: 5), - radius: 8, - onPressed: () async { - final circle = - await _controller?.addCircle(CircleOption( - center: LatLng(39.999391, 116.135972), - radius: 10000, - width: 10, - strokeColor: Colors.green, - )); - _circleList.add(circle); - }, - ), - new RoundButton( - text: " 绘制多边形 ", - radius: 8, - onPressed: () async { - final polygon = - await _controller?.addPolygon(PolygonOption( - latLngList: [ - LatLng(39.999391, 116.135972), - LatLng(39.898323, 116.057694), - LatLng(39.900430, 116.265061), - LatLng(39.955192, 116.140092), - ], - width: 10, - strokeColor: Colors.green, - )); - _polygonList.add(polygon); - }, - ), - new RoundButton( - text: " 曲线 ", - radius: 8, - margin: EdgeInsets.symmetric(horizontal: 5), - onPressed: () async { - _pointList = [ - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - getNextLatLng(), - ]; - _currentPolyline = - await _controller?.addPolyline(PolylineOption( - latLngList: _pointList, - width: 10, - strokeColor: Colors.green, - )); - }, - ), - new RoundButton( - text: " 地图缩放 ", - radius: 8, - onPressed: () async { - _controller?.zoomToSpan( - _pointList, - padding: EdgeInsets.only(top: 100), - ); - }, - ), - ], - ), - ) - ]), - ), - new Positioned( - // 左上角功能栏 - left: 10.0, - top: 60.0, - child: functionBar), - ])); - } -} diff --git a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart new file mode 100644 index 0000000..781b387 --- /dev/null +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -0,0 +1,167 @@ +import 'package:base_app/res/index.dart'; +import 'package:base_app/ui/widgets/common/button/round_button_widget.dart'; +import 'package:base_app/ui/widgets/map/zoom_plugin.dart'; +import 'package:base_app/utils/permission_util.dart'; +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:latlong/latlong.dart'; +// import 'package:location/location.dart'; + +final _assetsIcon = AssetImage('assets/images/qidian.png'); +String tiandituUrl = + 'http://t{s}.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=49826fb057bee77da2f1e9f525534178'; +String gaodeUrl = + 'http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'; +String arcgisUrl = + 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'; + +class TiandituMapPage extends StatefulWidget { + @override + _TiandituMapPageState createState() => _TiandituMapPageState(); +} + +class _TiandituMapPageState extends State { + // LocationData _currentLocation; //当前位置 + MapController mapController; + double rotation = 0.0; + + @override + void initState() { + super.initState(); + mapController = MapController(); + } + + @override + Widget build(BuildContext context) { + // 功能栏Widget + Widget functionBar = Container( + child: new Column( + children: [ + new FloatingActionButton( + // 回到当前位置按钮 + mini: true, + heroTag: 'gps_setting', + shape: new CircleBorder(), + backgroundColor: Colors.white, + child: Icon(Icons.gps_fixed, size: 26, color: Colours.gray_66), + onPressed: () async { + mapController.rotate(0.0); + }), + ], + )); + return Scaffold( + appBar: AppBar(title: const Text('自定义地图')), + body: new Stack(children: [ + Container( + height: double.infinity, + width: double.infinity, + color: Colors.white24, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: Container( + child: FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(39.9, 116.4), // 经纬度 + zoom: 13.0, // 缩放 + plugins: [ + ZoomButtonsPlugin(), + ], + ), + layers: [ + TileLayerOptions( + // wmsOptions: WMSTileLayerOptions( + // baseUrl: tiandituUrl, + // additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + // } + // // layers: ['s2cloudless-2018_3857'], + // ), + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, + // zoomOffset: 1.0, + subdomains: [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7' + ], + additionalOptions: { + // 'accessToken': + // '49826fb057bee77da2f1e9f525534178' + }), + MarkerLayerOptions( + markers: [ + new Marker( + width: 80.0, + height: 80.0, + point: LatLng(39.9, 116.4), + builder: (ctx) => new Container( + child: GestureDetector( + onTap: () { + showToast("click"); + }, + child: new FlutterLogo(), + )), + ), + ], + ), + ], + nonRotatedLayers: [ + ZoomButtonsPluginOption( + minZoom: 4, + maxZoom: 19, + mini: true, + padding: 10, + alignment: Alignment.bottomRight, + ), + ], + )), + ), + Container( + height: 55.0, + margin: EdgeInsets.all(10), + width: double.infinity, + color: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 8), + child: new Row( + children: [ + new RoundButton( + text: " 天地图 ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " 高德 ", + radius: 8, + onPressed: () {}, + ), + new RoundButton( + text: " arcgis ", + margin: EdgeInsets.symmetric(horizontal: 5), + radius: 8, + onPressed: () {}, + ) + ], + ), + ) + ]), + ), + new Positioned( + // 左上角功能栏 + left: 10.0, + top: 60.0, + child: functionBar), + ])); + } +} diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 08a230f..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,11 @@ import 'package:base_app/res/index.dart'; -import 'package:base_app/ui/pages/demo/mapPage/create_map_page.dart'; import 'package:base_app/ui/pages/main_left_page.dart'; import 'package:base_app/ui/widgets/common/button/large_button_widget.dart'; import 'package:base_app/utils/util_index.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'mapPage/draw_map_page.dart'; +import 'mapPage/tianditu_map_page.dart'; /// 简洁主页面 class MapPage extends StatelessWidget { @@ -16,25 +15,19 @@ @override Widget build(BuildContext context) { - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', + // 天地图实验 + Widget tiandituMap = new LargeButton( + text: '天地图', iconPath: "", onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); + NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } diff --git a/lib/ui/widgets/map/zoom_plugin.dart b/lib/ui/widgets/map/zoom_plugin.dart new file mode 100644 index 0000000..9f27b70 --- /dev/null +++ b/lib/ui/widgets/map/zoom_plugin.dart @@ -0,0 +1,119 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_map/flutter_map.dart'; +import 'package:flutter_map/plugin_api.dart'; + +class ZoomButtonsPluginOption extends LayerOptions { + final int minZoom; + final int maxZoom; + final bool mini; + final double padding; + final Alignment alignment; + final Color zoomInColor; + final Color zoomInColorIcon; + final Color zoomOutColor; + final Color zoomOutColorIcon; + final IconData zoomInIcon; + final IconData zoomOutIcon; + + ZoomButtonsPluginOption({ + Key key, + this.minZoom = 1, + this.maxZoom = 18, + this.mini = true, + this.padding = 2.0, + this.alignment = Alignment.topRight, + this.zoomInColor, + this.zoomInColorIcon, + this.zoomInIcon = Icons.zoom_in, + this.zoomOutColor, + this.zoomOutColorIcon, + this.zoomOutIcon = Icons.zoom_out, + Stream rebuild, + }) : super(key: key, rebuild: rebuild); +} + +class ZoomButtonsPlugin implements MapPlugin { + @override + Widget createLayer( + LayerOptions options, MapState mapState, Stream stream) { + if (options is ZoomButtonsPluginOption) { + return ZoomButtons(options, mapState, stream); + } + throw Exception('Unknown options type for ZoomButtonsPlugin: $options'); + } + + @override + bool supportsLayer(LayerOptions options) { + return options is ZoomButtonsPluginOption; + } +} + +class ZoomButtons extends StatelessWidget { + final ZoomButtonsPluginOption zoomButtonsOpts; + final MapState map; + final Stream stream; + final FitBoundsOptions options = + const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) + : super(key: zoomButtonsOpts.key); + + @override + Widget build(BuildContext context) { + return Align( + alignment: zoomButtonsOpts.alignment, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: zoomButtonsOpts.padding, + top: zoomButtonsOpts.padding, + right: zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomInButton', + mini: zoomButtonsOpts.mini, + backgroundColor: + zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom + 1; + if (zoom < zoomButtonsOpts.minZoom) { + zoom = zoomButtonsOpts.minZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomInIcon, + color: zoomButtonsOpts.zoomInColorIcon ?? + IconTheme.of(context).color), + ), + ), + Padding( + padding: EdgeInsets.all(zoomButtonsOpts.padding), + child: FloatingActionButton( + heroTag: 'zoomOutButton', + mini: zoomButtonsOpts.mini, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? + Theme.of(context).primaryColor, + onPressed: () { + var bounds = map.getBounds(); + var centerZoom = map.getBoundsCenterZoom(bounds, options); + var zoom = centerZoom.zoom - 1; + if (zoom > zoomButtonsOpts.maxZoom) { + zoom = zoomButtonsOpts.maxZoom as double; + } else { + map.move(centerZoom.center, zoom); + } + }, + child: Icon(zoomButtonsOpts.zoomOutIcon, + color: zoomButtonsOpts.zoomOutColorIcon ?? + IconTheme.of(context).color), + ), + ), + ], + ), + ); + } +} diff --git a/lib/utils/map_utils.dart b/lib/utils/map_utils.dart deleted file mode 100644 index dc6029d..0000000 --- a/lib/utils/map_utils.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:math'; - -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; - -/// 地图工具类 -class MapUtils { - ///计算两点距离 - ///[start] 第一个点坐标[lng,lat] - ///[end]第二个点坐标[lng,lat] - static double calculateDistance(start, end) { - if ((start != null) || (end != null)) { - double d1 = 0.01745329251994329; - double d2 = start[0]; //lng - double d3 = start[1]; //lat - double d4 = end[0]; //lng - double d5 = end[1]; //lat - d2 *= d1; - d3 *= d1; - d4 *= d1; - d5 *= d1; - double d6 = sin(d2); - double d7 = sin(d3); - double d8 = cos(d2); - double d9 = cos(d3); - double d10 = sin(d4); - double d11 = sin(d5); - double d12 = cos(d4); - double d13 = cos(d5); - List arrayOfDouble1 = List(3); - List arrayOfDouble2 = List(3); - arrayOfDouble1[0] = (d9 * d8); - arrayOfDouble1[1] = (d9 * d6); - arrayOfDouble1[2] = d7; - arrayOfDouble2[0] = (d13 * d12); - arrayOfDouble2[1] = (d13 * d10); - arrayOfDouble2[2] = d11; - double d14 = sqrt((arrayOfDouble1[0] - arrayOfDouble2[0]) * - (arrayOfDouble1[0] - arrayOfDouble2[0]) + - (arrayOfDouble1[1] - arrayOfDouble2[1]) * - (arrayOfDouble1[1] - arrayOfDouble2[1]) + - (arrayOfDouble1[2] - arrayOfDouble2[2]) * - (arrayOfDouble1[2] - arrayOfDouble2[2])); - print((asin(d14 / 2.0) * 12742001.579854401)); - return (asin(d14 / 2.0) * 12742001.579854401).abs(); - } else { - return 0.0; - } - } -} - -/// 获取随机坐标 -mixin NextLatLng { - final random = Random(); - - LatLng getNextLatLng({LatLng center}) { - center ??= LatLng(39.90960, 116.397228); - return LatLng( - center.latitude + random.nextDouble(), - center.longitude + random.nextDouble(), - ); - } - - List getNextBatchLatLng(int count) { - return [ - for (int i = 0; i < count; i++) - LatLng( - 39.90960 + random.nextDouble() * 4, - 116.397228 + random.nextDouble() * 4, - ) - ]; - } -} diff --git a/lib/utils/util_index.dart b/lib/utils/util_index.dart index b240611..e0ea1ac 100644 --- a/lib/utils/util_index.dart +++ b/lib/utils/util_index.dart @@ -2,7 +2,6 @@ export 'login_utils.dart'; export 'http_utils.dart'; export 'encrypt_helper.dart'; -export 'map_utils.dart'; export 'navigator_util.dart'; export 'route_util.dart'; export 'utils.dart'; diff --git a/pubspec.lock b/pubspec.lock index 74cac3b..0bcfd8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,27 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - amap_core_fluttify: + ansicolor: dependency: transitive description: - name: amap_core_fluttify + name: ansicolor url: "https://pub.flutter-io.cn" source: hosted - version: "0.9.5" - amap_map_fluttify: - dependency: "direct main" - description: - name: amap_map_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.24.0+3" - archive: - dependency: transitive - description: - name: archive - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.13" + version: "1.1.1" args: dependency: transitive description: @@ -35,14 +21,14 @@ name: asn1lib url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.5" + version: "0.8.1" async: dependency: transitive description: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.1" + version: "2.5.0-nullsafety.1" azlistview: dependency: "direct main" description: @@ -56,7 +42,7 @@ name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.1" cached_network_image: dependency: "direct main" description: @@ -64,34 +50,48 @@ url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.3" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "1.1.0-nullsafety.1" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.14.12" + version: "1.15.0-nullsafety.3" common_utils: dependency: transitive description: name: common_utils url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.1" + version: "1.2.4" + console_log_handler: + dependency: transitive + description: + name: console_log_handler + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.6" convert: dependency: transitive description: @@ -106,20 +106,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.0.8" - core_location_fluttify: - dependency: transitive - description: - name: core_location_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.2.4" crypto: dependency: transitive description: name: crypto url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.4" + version: "2.1.5" cupertino_icons: dependency: "direct main" description: @@ -147,7 +140,21 @@ name: encrypt url: "https://pub.flutter-io.cn" source: hosted - version: "4.0.2" + version: "4.1.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.2.0-nullsafety.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3" file: dependency: transitive description: @@ -188,18 +195,32 @@ url: "https://pub.flutter-io.cn" source: hosted version: "1.1.3" + flutter_image: + dependency: transitive + description: + name: flutter_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.0" flutter_localizations: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_map: + dependency: "direct main" + description: + name: flutter_map + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.11.0" flutter_plugin_android_lifecycle: dependency: transitive description: name: flutter_plugin_android_lifecycle url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.8" + version: "1.0.11" flutter_test: dependency: "direct dev" description: flutter @@ -210,13 +231,6 @@ description: flutter source: sdk version: "0.0.0" - foundation_fluttify: - dependency: transitive - description: - name: foundation_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.8.11" http: dependency: transitive description: @@ -231,27 +245,20 @@ url: "https://pub.flutter-io.cn" source: hosted version: "3.1.4" - image: - dependency: transitive - description: - name: image - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.12" image_picker: dependency: "direct main" description: name: image_picker url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.7+4" + version: "0.6.7+22" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.1.6" install_apk_plugin: dependency: "direct main" description: @@ -266,34 +273,62 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.16.1" - latlng: + latlong: dependency: transitive description: - name: latlng + name: latlong url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.2" + version: "0.6.1" + lists: + dependency: transitive + description: + name: lists + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.6" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.11.4" lpinyin: dependency: "direct main" description: name: lpinyin url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.9" + version: "1.1.1" matcher: dependency: transitive description: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.6" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety.3" + mgrs_dart: + dependency: transitive + description: + name: mgrs_dart + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.9.7" oktoast: dependency: "direct main" description: @@ -307,14 +342,14 @@ name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.4" + version: "1.8.0-nullsafety.1" path_provider: dependency: transitive description: name: path_provider url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.11" + version: "1.6.27" path_provider_linux: dependency: transitive description: @@ -328,42 +363,42 @@ name: path_provider_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.4+3" + version: "0.0.4+8" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+3" pedantic: dependency: transitive description: name: pedantic url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.0" + version: "1.9.2" permission_handler: dependency: "direct main" description: name: permission_handler url: "https://pub.flutter-io.cn" source: hosted - version: "5.0.1+1" + version: "5.1.0+2" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.4.0" + version: "2.0.2" photo_view: dependency: "direct main" description: @@ -378,27 +413,27 @@ url: "https://pub.flutter-io.cn" source: hosted version: "2.2.1" - platform_detect: - dependency: transitive - description: - name: platform_detect - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.4.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "1.0.3" pointycastle: dependency: transitive description: name: pointycastle url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2" + version: "2.0.1" + positioned_tap_detector: + dependency: transitive + description: + name: positioned_tap_detector + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" process: dependency: transitive description: @@ -406,13 +441,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "3.0.13" - pub_semver: + proj4dart: dependency: transitive description: - name: pub_semver + name: proj4dart url: "https://pub.flutter-io.cn" source: hosted - version: "1.4.4" + version: "1.0.5" pull_to_refresh: dependency: "direct main" description: @@ -426,7 +461,7 @@ name: quiver url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.3" + version: "2.1.5" rational: dependency: transitive description: @@ -447,28 +482,28 @@ name: share url: "https://pub.flutter-io.cn" source: hosted - version: "0.6.4+3" + version: "0.6.5+4" shared_preferences: dependency: transitive description: name: shared_preferences url: "https://pub.flutter-io.cn" source: hosted - version: "0.5.8" + version: "0.5.12+4" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.2+1" + version: "0.0.2+4" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+10" + version: "0.0.1+11" shared_preferences_platform_interface: dependency: transitive description: @@ -483,6 +518,13 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.1.2+7" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.2+3" sky_engine: dependency: transitive description: flutter @@ -494,49 +536,49 @@ name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.7.0" + version: "1.8.0-nullsafety.2" sp_util: dependency: transitive description: name: sp_util url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "1.0.2" sqflite: dependency: "direct main" description: name: sqflite url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.1" + version: "1.3.2+3" sqflite_common: dependency: transitive description: name: sqflite_common url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.2+1" + version: "1.0.3+1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.5" + version: "1.1.0-nullsafety.1" synchronized: dependency: transitive description: @@ -550,91 +592,133 @@ name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.15" + version: "0.2.19-nullsafety.2" + transparent_image: + dependency: transitive + description: + name: transparent_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.0" + tuple: + dependency: transitive + description: + name: tuple + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" typed_data: dependency: transitive description: name: typed_data url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.3" + unicode: + dependency: transitive + description: + name: unicode + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.4" url_launcher: dependency: "direct main" description: name: url_launcher url: "https://pub.flutter-io.cn" source: hosted - version: "5.5.0" + version: "5.7.10" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+1" + version: "0.0.1+4" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+7" + version: "0.0.1+9" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.7" + version: "1.0.9" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.2" + version: "0.1.5+3" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+3" uuid: dependency: transitive description: name: uuid url: "https://pub.flutter-io.cn" source: hosted - version: "2.2.0" + version: "2.2.2" + validate: + dependency: transitive + description: + name: validate + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.3" webview_flutter: dependency: "direct main" description: name: webview_flutter url: "https://pub.flutter-io.cn" source: hosted - version: "0.3.22+1" + version: "0.3.24" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.4+1" + wkt_parser: + dependency: transitive + description: + name: wkt_parser + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.7" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.0" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.flutter-io.cn" - source: hosted - version: "3.6.1" + version: "0.1.2" sdks: - dart: ">=2.8.0 <3.0.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + dart: ">=2.10.2 <2.11.0" + flutter: ">=1.22.2 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 5875161..7d3de0b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,8 +65,10 @@ pull_to_refresh: 1.1.6 # 权限请求插件 permission_handler: ^5.0.0+hotfix.6 - # 高德地图 - amap_map_fluttify: ^0.24.0+3 + # flutter map 基于leaflet的地图包 + flutter_map: ^0.11.0 + #获取定位包 + # location: ^3.2.4 diff --git a/test/widget_test.dart b/test/widget_test.dart index faa94f2..c58fc2f 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,15 +13,15 @@ void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); // ����App��� + await tester.pumpWidget(MyApp()); // ����App��� - // ��find���������Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); // ���������һ�� - expect(find.text('1'), findsNothing); // ���������0�� + // ��find���������Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); // ���������һ�� + expect(find.text('1'), findsNothing); // ���������0�� // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); // ģ�������� - await tester.pump(); // �ؽ���� + await tester.tap(find.byIcon(Icons.add)); // ģ�������� + await tester.pump(); // �ؽ���� // Verify that our counter has incremented. expect(find.text('0'), findsNothing);