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 index 33050c6..781b387 100644 --- a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -82,8 +82,8 @@ // } // // layers: ['s2cloudless-2018_3857'], // ), - // urlTemplate: tiandituUrl, - urlTemplate: arcgisUrl, + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, // zoomOffset: 1.0, subdomains: [ '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 index 33050c6..781b387 100644 --- a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -82,8 +82,8 @@ // } // // layers: ['s2cloudless-2018_3857'], // ), - // urlTemplate: tiandituUrl, - urlTemplate: arcgisUrl, + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, // zoomOffset: 1.0, subdomains: [ '0', diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 8f313b5..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,10 @@ 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'; /// 简洁主页面 @@ -24,25 +22,12 @@ onTap: () { NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); - }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, tiandituMap, 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 index 33050c6..781b387 100644 --- a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -82,8 +82,8 @@ // } // // layers: ['s2cloudless-2018_3857'], // ), - // urlTemplate: tiandituUrl, - urlTemplate: arcgisUrl, + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, // zoomOffset: 1.0, subdomains: [ '0', diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 8f313b5..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,10 @@ 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'; /// 简洁主页面 @@ -24,25 +22,12 @@ onTap: () { NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); - }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, tiandituMap, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } 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 index 33050c6..781b387 100644 --- a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -82,8 +82,8 @@ // } // // layers: ['s2cloudless-2018_3857'], // ), - // urlTemplate: tiandituUrl, - urlTemplate: arcgisUrl, + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, // zoomOffset: 1.0, subdomains: [ '0', diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 8f313b5..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,10 @@ 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'; /// 简洁主页面 @@ -24,25 +22,12 @@ onTap: () { NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); - }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, tiandituMap, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } 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 index 33050c6..781b387 100644 --- a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -82,8 +82,8 @@ // } // // layers: ['s2cloudless-2018_3857'], // ), - // urlTemplate: tiandituUrl, - urlTemplate: arcgisUrl, + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, // zoomOffset: 1.0, subdomains: [ '0', diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 8f313b5..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,10 @@ 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'; /// 简洁主页面 @@ -24,25 +22,12 @@ onTap: () { NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); - }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, tiandituMap, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } 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 536121b..0bcfd8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,20 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - amap_core_fluttify: - dependency: transitive - description: - name: amap_core_fluttify - 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" ansicolor: dependency: transitive description: @@ -120,13 +106,6 @@ 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: @@ -252,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.12" http: dependency: transitive description: @@ -301,13 +273,6 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.16.1" - latlng: - dependency: transitive - description: - name: latlng - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.0.2" latlong: dependency: transitive description: 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 index 33050c6..781b387 100644 --- a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -82,8 +82,8 @@ // } // // layers: ['s2cloudless-2018_3857'], // ), - // urlTemplate: tiandituUrl, - urlTemplate: arcgisUrl, + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, // zoomOffset: 1.0, subdomains: [ '0', diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 8f313b5..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,10 @@ 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'; /// 简洁主页面 @@ -24,25 +22,12 @@ onTap: () { NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); - }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, tiandituMap, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } 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 536121b..0bcfd8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,20 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - amap_core_fluttify: - dependency: transitive - description: - name: amap_core_fluttify - 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" ansicolor: dependency: transitive description: @@ -120,13 +106,6 @@ 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: @@ -252,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.12" http: dependency: transitive description: @@ -301,13 +273,6 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.16.1" - latlng: - dependency: transitive - description: - name: latlng - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.0.2" latlong: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4d412e4..7d3de0b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,8 +65,6 @@ 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 #获取定位包 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 index 33050c6..781b387 100644 --- a/lib/ui/pages/demo/mapPage/tianditu_map_page.dart +++ b/lib/ui/pages/demo/mapPage/tianditu_map_page.dart @@ -82,8 +82,8 @@ // } // // layers: ['s2cloudless-2018_3857'], // ), - // urlTemplate: tiandituUrl, - urlTemplate: arcgisUrl, + urlTemplate: tiandituUrl, + // urlTemplate: arcgisUrl, // zoomOffset: 1.0, subdomains: [ '0', diff --git a/lib/ui/pages/demo/map_page.dart b/lib/ui/pages/demo/map_page.dart index 8f313b5..f33b9d3 100644 --- a/lib/ui/pages/demo/map_page.dart +++ b/lib/ui/pages/demo/map_page.dart @@ -1,12 +1,10 @@ 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'; /// 简洁主页面 @@ -24,25 +22,12 @@ onTap: () { NavigatorUtil.pushPage(context, new TiandituMapPage()); }); - // 系统设置 - Widget createMap = new LargeButton( - text: '创建地图', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new CreateMapPage()); - }); - // 系统设置 - Widget drawMap = new LargeButton( - text: '地图绘制', - iconPath: "", - onTap: () { - NavigatorUtil.pushPage(context, new DrawMapPage()); - }); + // 全局 return new SingleChildScrollView( physics: BouncingScrollPhysics(), child: new Column( - children: [Gaps.vGap15, tiandituMap, createMap, drawMap], + children: [Gaps.vGap15, tiandituMap], ), ); } 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 536121b..0bcfd8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,20 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - amap_core_fluttify: - dependency: transitive - description: - name: amap_core_fluttify - 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" ansicolor: dependency: transitive description: @@ -120,13 +106,6 @@ 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: @@ -252,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.12" http: dependency: transitive description: @@ -301,13 +273,6 @@ url: "https://pub.flutter-io.cn" source: hosted version: "0.16.1" - latlng: - dependency: transitive - description: - name: latlng - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.0.2" latlong: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4d412e4..7d3de0b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,8 +65,6 @@ 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 #获取定位包 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);