release: 1.0.12
This commit is contained in:
@ -18,7 +18,7 @@ class CustomInfoWindowDemoPage extends StatefulWidget {
|
||||
class _State extends State<CustomInfoWindowDemoPage> {
|
||||
static final LatLng mapCenter = const LatLng(39.909187, 116.397451);
|
||||
|
||||
Map<String, Marker> _markers = <String, Marker>{};
|
||||
final Map<String, Marker> _markers = <String, Marker>{};
|
||||
BitmapDescriptor? _markerIcon;
|
||||
String? selectedMarkerId;
|
||||
bool showInfoWindow = false;
|
||||
@ -77,7 +77,7 @@ class _State extends State<CustomInfoWindowDemoPage> {
|
||||
}
|
||||
|
||||
void _removeAll() {
|
||||
if (_markers.length > 0) {
|
||||
if (_markers.isNotEmpty) {
|
||||
setState(() {
|
||||
_markers.clear();
|
||||
selectedMarkerId = null.toString();
|
||||
@ -87,7 +87,7 @@ class _State extends State<CustomInfoWindowDemoPage> {
|
||||
|
||||
void _changeInfo() async {
|
||||
final Marker marker = _markers[selectedMarkerId]!;
|
||||
final String newTitle = marker.infoWindow.title! + '*';
|
||||
final String newTitle = '${marker.infoWindow.title!}*';
|
||||
if (selectedMarkerId != null) {
|
||||
setState(() {
|
||||
_markers[selectedMarkerId!] = marker.copyWith(
|
||||
@ -183,9 +183,7 @@ class _State extends State<CustomInfoWindowDemoPage> {
|
||||
Widget build(BuildContext context) {
|
||||
///以下几种获取自定图片的方式使用其中一种即可。
|
||||
//最简单的方式
|
||||
if (null == _markerIcon) {
|
||||
_markerIcon = BitmapDescriptor.fromIconPath('assets/location_marker.png');
|
||||
}
|
||||
_markerIcon ??= BitmapDescriptor.fromIconPath('assets/location_marker.png');
|
||||
|
||||
AMapWidget map = AMapWidget(
|
||||
onMapCreated: _onMapCreated,
|
||||
@ -245,7 +243,7 @@ class _State extends State<CustomInfoWindowDemoPage> {
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('全部移除'),
|
||||
onPressed: _markers.length > 0 ? _removeAll : null,
|
||||
onPressed: _markers.isNotEmpty ? _removeAll : null,
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('允许拖动'),
|
||||
@ -288,8 +286,7 @@ class _State extends State<CustomInfoWindowDemoPage> {
|
||||
}
|
||||
|
||||
class CustomInfoWindowAdapter extends BaseInfoWindowAdapter {
|
||||
CustomInfoWindowAdapter(AMapController? controller, this.selectedMarkerId)
|
||||
: super(controller);
|
||||
CustomInfoWindowAdapter(super.controller, this.selectedMarkerId);
|
||||
|
||||
final String? selectedMarkerId;
|
||||
|
||||
|
@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class MarkerAddAfterMapPage extends StatefulWidget {
|
||||
@override
|
||||
_BodyState createState() => _BodyState();
|
||||
State<MarkerAddAfterMapPage> createState() => _BodyState();
|
||||
}
|
||||
|
||||
class _BodyState extends State<MarkerAddAfterMapPage> {
|
||||
@ -14,16 +14,16 @@ class _BodyState extends State<MarkerAddAfterMapPage> {
|
||||
LatLng _currentLatLng = defaultPosition;
|
||||
//添加一个marker
|
||||
void _addMarker() {
|
||||
final _markerPosition =
|
||||
final markerPosition =
|
||||
LatLng(_currentLatLng.latitude, _currentLatLng.longitude + 2 / 1000);
|
||||
final Marker marker = Marker(
|
||||
position: _markerPosition,
|
||||
position: markerPosition,
|
||||
//使用默认hue的方式设置Marker的图标
|
||||
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueOrange),
|
||||
);
|
||||
//调用setState触发AMapWidget的更新,从而完成marker的添加
|
||||
setState(() {
|
||||
_currentLatLng = _markerPosition;
|
||||
_currentLatLng = markerPosition;
|
||||
//将新的marker添加到map里
|
||||
_markers[marker.id] = marker;
|
||||
});
|
||||
@ -33,16 +33,16 @@ class _BodyState extends State<MarkerAddAfterMapPage> {
|
||||
return TextButton(
|
||||
onPressed: onPressed,
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all(
|
||||
shape: WidgetStateProperty.all(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10))),
|
||||
//文字颜色
|
||||
foregroundColor: MaterialStateProperty.all(Colors.white),
|
||||
foregroundColor: WidgetStateProperty.all(Colors.white),
|
||||
//水波纹颜色
|
||||
overlayColor: MaterialStateProperty.all(Colors.blueAccent),
|
||||
overlayColor: WidgetStateProperty.all(Colors.blueAccent),
|
||||
//背景颜色
|
||||
backgroundColor: MaterialStateProperty.resolveWith((states) {
|
||||
backgroundColor: WidgetStateProperty.resolveWith((states) {
|
||||
//设置按下时的背景颜色
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return Colors.blueAccent;
|
||||
}
|
||||
//默认背景颜色
|
||||
|
@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class MarkerAddWithMapPage extends StatefulWidget {
|
||||
@override
|
||||
_BodyState createState() => _BodyState();
|
||||
State<MarkerAddWithMapPage> createState() => _BodyState();
|
||||
}
|
||||
|
||||
class _BodyState extends State<MarkerAddWithMapPage> {
|
||||
|
@ -19,7 +19,7 @@ class MarkerConfigDemoPage extends StatefulWidget {
|
||||
class _State extends State<MarkerConfigDemoPage> {
|
||||
static final LatLng mapCenter = const LatLng(39.909187, 116.397451);
|
||||
|
||||
Map<String, Marker> _markers = <String, Marker>{};
|
||||
final Map<String, Marker> _markers = <String, Marker>{};
|
||||
BitmapDescriptor? _markerIcon;
|
||||
String? selectedMarkerId;
|
||||
|
||||
@ -27,11 +27,11 @@ class _State extends State<MarkerConfigDemoPage> {
|
||||
LatLng latLng = LatLng(mapCenter.latitude + sin(pi / 12.0) / 20.0,
|
||||
mapCenter.longitude + cos(pi / 12.0) / 20.0);
|
||||
try {
|
||||
print('-latLng---------${latLng}');
|
||||
print('-latLng---------$latLng');
|
||||
ScreenCoordinate coordinate = await controller.toScreenCoordinate(latLng);
|
||||
print('-coordinate---------${coordinate}');
|
||||
print('-coordinate---------$coordinate');
|
||||
LatLng reLatLng = await controller.fromScreenCoordinate(coordinate);
|
||||
print('-reLatLng---------${reLatLng}');
|
||||
print('-reLatLng---------$reLatLng');
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
@ -119,7 +119,7 @@ class _State extends State<MarkerConfigDemoPage> {
|
||||
}
|
||||
|
||||
void _removeAll() {
|
||||
if (_markers.length > 0) {
|
||||
if (_markers.isNotEmpty) {
|
||||
setState(() {
|
||||
_markers.clear();
|
||||
selectedMarkerId = null.toString();
|
||||
@ -129,7 +129,7 @@ class _State extends State<MarkerConfigDemoPage> {
|
||||
|
||||
void _changeInfo() async {
|
||||
final Marker marker = _markers[selectedMarkerId]!;
|
||||
final String newTitle = marker.infoWindow.title! + '*';
|
||||
final String newTitle = '${marker.infoWindow.title!}*';
|
||||
if (selectedMarkerId != null) {
|
||||
setState(() {
|
||||
_markers[selectedMarkerId!] = marker.copyWith(
|
||||
@ -233,14 +233,12 @@ class _State extends State<MarkerConfigDemoPage> {
|
||||
Widget build(BuildContext context) {
|
||||
///以下几种获取自定图片的方式使用其中一种即可。
|
||||
//最简单的方式
|
||||
if (null == _markerIcon) {
|
||||
_markerIcon = BitmapDescriptor.fromIconPath('assets/location_marker.png');
|
||||
}
|
||||
_markerIcon ??= BitmapDescriptor.fromIconPath('assets/location_marker.png');
|
||||
|
||||
//通过BitmapDescriptor.fromAssetImage的方式获取图片
|
||||
// _createMarkerImageFromAsset(context);
|
||||
_createMarkerImageFromAsset(context);
|
||||
//通过BitmapDescriptor.fromBytes的方式获取图片
|
||||
// _createMarkerImageFromBytes(context);
|
||||
_createMarkerImageFromBytes(context);
|
||||
|
||||
final AMapWidget map = AMapWidget(
|
||||
onMapCreated: _onMapCreated,
|
||||
@ -299,7 +297,7 @@ class _State extends State<MarkerConfigDemoPage> {
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('全部移除'),
|
||||
onPressed: _markers.length > 0 ? _removeAll : null,
|
||||
onPressed: _markers.isNotEmpty ? _removeAll : null,
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('允许拖动'),
|
||||
|
@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class MarkerCustomIconPage extends StatefulWidget {
|
||||
@override
|
||||
_BodyState createState() => _BodyState();
|
||||
State<MarkerCustomIconPage> createState() => _BodyState();
|
||||
}
|
||||
|
||||
class _BodyState extends State<MarkerCustomIconPage> {
|
||||
@ -42,16 +42,16 @@ class _BodyState extends State<MarkerCustomIconPage> {
|
||||
return TextButton(
|
||||
onPressed: onPressed,
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all(
|
||||
shape: WidgetStateProperty.all(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10))),
|
||||
//文字颜色
|
||||
foregroundColor: MaterialStateProperty.all(Colors.white),
|
||||
foregroundColor: WidgetStateProperty.all(Colors.white),
|
||||
//水波纹颜色
|
||||
overlayColor: MaterialStateProperty.all(Colors.blueAccent),
|
||||
overlayColor: WidgetStateProperty.all(Colors.blueAccent),
|
||||
//背景颜色
|
||||
backgroundColor: MaterialStateProperty.resolveWith((states) {
|
||||
backgroundColor: WidgetStateProperty.resolveWith((states) {
|
||||
//设置按下时的背景颜色
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return Colors.blueAccent;
|
||||
}
|
||||
//默认背景颜色
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:amap_map_example/widgets/amap_switch_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:x_amap_base/x_amap_base.dart';
|
||||
@ -24,7 +23,7 @@ class _State extends State<PolygonDemoPage> {
|
||||
Colors.pink,
|
||||
];
|
||||
|
||||
Map<String, Polygon> _polygons = <String, Polygon>{};
|
||||
final Map<String, Polygon> _polygons = <String, Polygon>{};
|
||||
String? selectedPolygonId;
|
||||
|
||||
void _onMapCreated(AMapController controller) {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:amap_map_example/widgets/amap_switch_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:x_amap_base/x_amap_base.dart';
|
||||
@ -23,7 +22,7 @@ class _State extends State<PolylineDemoPage> {
|
||||
Colors.green,
|
||||
Colors.pink,
|
||||
];
|
||||
Map<String, Polyline> _polylines = <String, Polyline>{};
|
||||
final Map<String, Polyline> _polylines = <String, Polyline>{};
|
||||
String? selectedPolylineId;
|
||||
|
||||
void _onMapCreated(AMapController controller) {}
|
||||
@ -64,7 +63,7 @@ class _State extends State<PolylineDemoPage> {
|
||||
}
|
||||
|
||||
void _changeWidth() {
|
||||
final Polyline? selectedPolyline = _polylines[selectedPolylineId]!;
|
||||
final Polyline? selectedPolyline = _polylines[selectedPolylineId];
|
||||
//有选中的Polyline
|
||||
if (selectedPolyline != null) {
|
||||
double currentWidth = selectedPolyline.width;
|
||||
@ -109,7 +108,7 @@ class _State extends State<PolylineDemoPage> {
|
||||
}
|
||||
|
||||
void _changeCapType() {
|
||||
final Polyline? polyline = _polylines[selectedPolylineId]!;
|
||||
final Polyline? polyline = _polylines[selectedPolylineId];
|
||||
if (polyline == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:x_amap_base/x_amap_base.dart';
|
||||
@ -22,7 +21,7 @@ class _State extends State<PolylineGeodesicDemoPage> {
|
||||
Colors.green,
|
||||
Colors.pink,
|
||||
];
|
||||
Map<String, Polyline> _polylines = <String, Polyline>{};
|
||||
final Map<String, Polyline> _polylines = <String, Polyline>{};
|
||||
late String selectedPolylineId;
|
||||
AMapController? _controller;
|
||||
|
||||
@ -89,16 +88,16 @@ class _State extends State<PolylineGeodesicDemoPage> {
|
||||
child: TextButton(
|
||||
onPressed: _add,
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all(RoundedRectangleBorder(
|
||||
shape: WidgetStateProperty.all(RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10))),
|
||||
//文字颜色
|
||||
foregroundColor: MaterialStateProperty.all(Colors.white),
|
||||
foregroundColor: WidgetStateProperty.all(Colors.white),
|
||||
//水波纹颜色
|
||||
overlayColor: MaterialStateProperty.all(Colors.blueAccent),
|
||||
overlayColor: WidgetStateProperty.all(Colors.blueAccent),
|
||||
//背景颜色
|
||||
backgroundColor: MaterialStateProperty.resolveWith((states) {
|
||||
backgroundColor: WidgetStateProperty.resolveWith((states) {
|
||||
//设置按下时的背景颜色
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return Colors.blueAccent;
|
||||
}
|
||||
//默认背景颜色
|
||||
|
@ -13,7 +13,7 @@ class PolylineTextureDemoPage extends StatefulWidget {
|
||||
class _State extends State<PolylineTextureDemoPage> {
|
||||
_State();
|
||||
|
||||
Map<String, Polyline> _polylines = <String, Polyline>{};
|
||||
final Map<String, Polyline> _polylines = <String, Polyline>{};
|
||||
late String selectedPolylineId;
|
||||
|
||||
void _onMapCreated(AMapController controller) {}
|
||||
@ -76,16 +76,16 @@ class _State extends State<PolylineTextureDemoPage> {
|
||||
child: TextButton(
|
||||
onPressed: _add,
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all(RoundedRectangleBorder(
|
||||
shape: WidgetStateProperty.all(RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10))),
|
||||
//文字颜色
|
||||
foregroundColor: MaterialStateProperty.all(Colors.white),
|
||||
foregroundColor: WidgetStateProperty.all(Colors.white),
|
||||
//水波纹颜色
|
||||
overlayColor: MaterialStateProperty.all(Colors.blueAccent),
|
||||
overlayColor: WidgetStateProperty.all(Colors.blueAccent),
|
||||
//背景颜色
|
||||
backgroundColor: MaterialStateProperty.resolveWith((states) {
|
||||
backgroundColor: WidgetStateProperty.resolveWith((states) {
|
||||
//设置按下时的背景颜色
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return Colors.blueAccent;
|
||||
}
|
||||
//默认背景颜色
|
||||
|
Reference in New Issue
Block a user