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<CreateMapPage> { AmapController _controller; // 地图controller bool showTraffic = false; Map<String, MapType> 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: <Widget>[ 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: <Widget>[ 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: <Widget>[ 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), ])); } }