From 0a6e9c71195024ad5a686d07dc984b49f112a62f Mon Sep 17 00:00:00 2001 From: Kuloud Date: Mon, 26 Aug 2024 09:55:49 +0800 Subject: [PATCH] release: 1.0.12 --- .github/workflows/publish.yml | 4 +- CHANGELOG.md | 4 ++ example/lib/category_list_item.dart | 12 ++--- example/lib/main.dart | 2 - .../interactive/map_gestures_options.dart | 8 ++-- .../lib/pages/interactive/map_ui_options.dart | 12 ++--- .../pages/interactive/move_camera_demo.dart | 22 ++++----- .../lib/pages/interactive/poi_click_demo.dart | 4 +- .../lib/pages/interactive/snapshot_demo.dart | 10 ++-- example/lib/pages/map/change_map_lang.dart | 4 +- example/lib/pages/map/change_map_type.dart | 4 +- example/lib/pages/map/custom_map_style.dart | 6 +-- example/lib/pages/map/limit_map_bounds.dart | 4 +- example/lib/pages/map/map_all_config.dart | 48 +++++++++---------- example/lib/pages/map/map_my_location.dart | 4 +- example/lib/pages/map/min_max_zoom.dart | 4 +- example/lib/pages/map/show_map_page.dart | 2 +- .../pages/overlays/custom_info_window.dart | 15 +++--- .../pages/overlays/marker_add_after_map.dart | 18 +++---- .../pages/overlays/marker_add_with_map.dart | 2 +- example/lib/pages/overlays/marker_config.dart | 22 ++++----- .../pages/overlays/marker_custom_icon.dart | 12 ++--- example/lib/pages/overlays/place_polygon.dart | 3 +- .../lib/pages/overlays/place_polyline.dart | 7 ++- .../lib/pages/overlays/polyline_geodesic.dart | 13 +++-- .../lib/pages/overlays/polyline_texture.dart | 12 ++--- example/lib/routes.dart | 2 +- example/lib/theme.dart | 20 -------- example/lib/widgets/amap_gridview.dart | 2 +- example/lib/widgets/amap_radio_group.dart | 2 +- lib/src/amap_widget.dart | 2 +- lib/src/types/base_overlay.dart | 31 ++++++++---- lib/src/types/marker.dart | 11 +++++ lib/src/types/polygon.dart | 5 +- lib/src/types/polyline.dart | 9 ++++ pubspec.yaml | 2 +- 36 files changed, 172 insertions(+), 172 deletions(-) delete mode 100644 example/lib/theme.dart diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e2b8685..8d4f174 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -40,8 +40,8 @@ jobs: tag_name: v${{ steps.package_publisher.outputs.localVersion }} title: Release ${{ steps.package_publisher.outputs.localVersion }} body: | - Automated release for version ${{ steps.package_publisher.outputs.localVersion }} - Changes in this release: + Automated release for version ${{ steps.package_publisher.outputs.localVersion }}\n + Changes in this release:\n ${{ env.git_log }} draft: false prerelease: false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 102a0f8..0d7625b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.12 +2024-08-26 +* code lint + ## 1.0.11 2024-08-25 * 升级amap iOS sdk版本 10.0.900 | 2024-08-23 diff --git a/example/lib/category_list_item.dart b/example/lib/category_list_item.dart index 87d55f5..bb7d0d2 100644 --- a/example/lib/category_list_item.dart +++ b/example/lib/category_list_item.dart @@ -172,7 +172,6 @@ class _CategoryHeader extends StatelessWidget { margin: margin, child: Material( shape: RoundedRectangleBorder(borderRadius: borderRadius), - color: colorScheme.onBackground, clipBehavior: Clip.antiAlias, child: SizedBox( width: MediaQuery.of(context).size.width, @@ -198,10 +197,7 @@ class _CategoryHeader extends StatelessWidget { padding: const EdgeInsetsDirectional.only(start: 8), child: Text( category.toDisplayTitle(), - style: - Theme.of(context).textTheme.headlineMedium!.apply( - color: colorScheme.onSurface, - ), + style: Theme.of(context).textTheme.headlineMedium, ), ), ], @@ -268,7 +264,6 @@ class CategoryDemoItem extends StatelessWidget { return Material( // Makes integration tests possible. key: ValueKey(demo.describe), - color: Theme.of(context).colorScheme.surface, child: MergeSemantics( child: InkWell( onTap: () { @@ -292,8 +287,7 @@ class CategoryDemoItem extends StatelessWidget { children: [ Text( demo.title, - style: textTheme.titleMedium! - .apply(color: colorScheme.onSurface), + style: textTheme.titleMedium, ), Text( demo.subtitle, @@ -305,7 +299,7 @@ class CategoryDemoItem extends StatelessWidget { Divider( thickness: 1, height: 1, - color: Theme.of(context).colorScheme.background, + color: Theme.of(context).colorScheme.surface, ), ], ), diff --git a/example/lib/main.dart b/example/lib/main.dart index 3da3abc..80fcedd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,7 +4,6 @@ import 'package:amap_map_example/category_list_item.dart'; import 'package:amap_map_example/const_config.dart'; import 'package:amap_map_example/data/demos.dart'; import 'package:amap_map_example/routes.dart'; -import 'package:amap_map_example/theme.dart'; import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -95,7 +94,6 @@ class _AMapDemoState extends State void main() { runApp(MaterialApp( - theme: ThemeData(colorScheme: DemoThemeData.lightColorScheme), themeMode: ThemeMode.light, onGenerateRoute: RouteConfig.onGenerateRoute, home: AMapDemo())); diff --git a/example/lib/pages/interactive/map_gestures_options.dart b/example/lib/pages/interactive/map_gestures_options.dart index 017ac6f..c615528 100644 --- a/example/lib/pages/interactive/map_gestures_options.dart +++ b/example/lib/pages/interactive/map_gestures_options.dart @@ -4,10 +4,10 @@ import 'package:amap_map_example/widgets/amap_switch_button.dart'; import 'package:flutter/material.dart'; class GesturesDemoPage extends StatefulWidget { - GesturesDemoPage({Key? key}) : super(key: key); + GesturesDemoPage({super.key}); @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { @@ -71,7 +71,7 @@ class _BodyState extends State { }, ), ]; - Widget _gesturesOptiosWeidget() { + Widget gesturesOptiosWeidget() { return Container( padding: EdgeInsets.all(5), child: Column( @@ -103,7 +103,7 @@ class _BodyState extends State { Expanded( child: SingleChildScrollView( child: Container( - child: _gesturesOptiosWeidget(), + child: gesturesOptiosWeidget(), ), ), ), diff --git a/example/lib/pages/interactive/map_ui_options.dart b/example/lib/pages/interactive/map_ui_options.dart index b960ac8..2762458 100644 --- a/example/lib/pages/interactive/map_ui_options.dart +++ b/example/lib/pages/interactive/map_ui_options.dart @@ -6,10 +6,10 @@ import 'package:flutter/material.dart'; import 'package:x_amap_base/x_amap_base.dart'; class MapUIDemoPage extends StatefulWidget { - MapUIDemoPage({Key? key}) : super(key: key); + MapUIDemoPage({super.key}); @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { @@ -52,7 +52,7 @@ class _BodyState extends State { ); //ui控制 - final List _uiOptions = [ + final List uiOptions = [ AMapSwitchButton( label: Text('显示路况'), defaultValue: _trafficEnabled, @@ -100,7 +100,7 @@ class _BodyState extends State { ), ]; - Widget _uiOptionsWidget() { + Widget uiOptionsWidget() { return Container( padding: EdgeInsets.all(5), child: Column( @@ -110,7 +110,7 @@ class _BodyState extends State { Text('UI操作', style: TextStyle(fontWeight: FontWeight.w600)), Container( padding: EdgeInsets.only(left: 10), - child: AMapGradView(childrenWidgets: _uiOptions), + child: AMapGradView(childrenWidgets: uiOptions), ), AMapRadioGroup( groupLabel: 'Logo位置', @@ -169,7 +169,7 @@ class _BodyState extends State { Expanded( child: SingleChildScrollView( child: Container( - child: _uiOptionsWidget(), + child: uiOptionsWidget(), ), ), ), diff --git a/example/lib/pages/interactive/move_camera_demo.dart b/example/lib/pages/interactive/move_camera_demo.dart index 78789b3..010373f 100644 --- a/example/lib/pages/interactive/move_camera_demo.dart +++ b/example/lib/pages/interactive/move_camera_demo.dart @@ -4,10 +4,10 @@ import 'package:amap_map_example/widgets/amap_gridview.dart'; import 'package:flutter/material.dart'; class MoveCameraDemoPage extends StatefulWidget { - MoveCameraDemoPage({Key? key}) : super(key: key); + MoveCameraDemoPage({super.key}); @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { @@ -20,14 +20,14 @@ class _BodyState extends State { onCameraMove: _onCameraMove, onCameraMoveEnd: _onCameraMoveEnd, ); - List _optionsWidget = [ + List optionsWidget = [ _createMyFloatButton('改变显示区域', _changeLatLngBounds), _createMyFloatButton('改变中心点', _changeCameraPosition), _createMyFloatButton('改变缩放级别到18', _changeCameraZoom), _createMyFloatButton('按照像素移动地图', _scrollBy), ]; - Widget _cameraOptions() { + Widget cameraOptions() { return Container( padding: EdgeInsets.all(5), child: Column( @@ -36,7 +36,7 @@ class _BodyState extends State { children: [ Container( child: AMapGradView( - childrenWidgets: _optionsWidget, + childrenWidgets: optionsWidget, ), ), ], @@ -112,7 +112,7 @@ class _BodyState extends State { ) : SizedBox(), Container( - child: _cameraOptions(), + child: cameraOptions(), ), ], ), @@ -204,16 +204,16 @@ class _BodyState extends State { 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; } //默认背景颜色 diff --git a/example/lib/pages/interactive/poi_click_demo.dart b/example/lib/pages/interactive/poi_click_demo.dart index 27946bb..a6cf6f2 100644 --- a/example/lib/pages/interactive/poi_click_demo.dart +++ b/example/lib/pages/interactive/poi_click_demo.dart @@ -3,10 +3,10 @@ import 'package:x_amap_base/x_amap_base.dart'; import 'package:flutter/material.dart'; class PoiClickDemoPage extends StatefulWidget { - PoiClickDemoPage({Key? key}) : super(key: key); + PoiClickDemoPage({super.key}); @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { diff --git a/example/lib/pages/interactive/snapshot_demo.dart b/example/lib/pages/interactive/snapshot_demo.dart index c5e0c83..d7a2ade 100644 --- a/example/lib/pages/interactive/snapshot_demo.dart +++ b/example/lib/pages/interactive/snapshot_demo.dart @@ -32,16 +32,16 @@ class _SnapShotState extends State { child: TextButton( child: Text('截屏'), 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; } //默认背景颜色 diff --git a/example/lib/pages/map/change_map_lang.dart b/example/lib/pages/map/change_map_lang.dart index 2d8b674..4839f6b 100644 --- a/example/lib/pages/map/change_map_lang.dart +++ b/example/lib/pages/map/change_map_lang.dart @@ -14,10 +14,10 @@ import 'package:amap_map_example/widgets/amap_radio_group.dart'; import 'package:flutter/material.dart'; class ChangeMapLangPage extends StatefulWidget { - ChangeMapLangPage({Key? key}) : super(key: key); + ChangeMapLangPage({super.key}); @override - _PageBodyState createState() => _PageBodyState(); + State createState() => _PageBodyState(); } class _PageBodyState extends State { diff --git a/example/lib/pages/map/change_map_type.dart b/example/lib/pages/map/change_map_type.dart index 292703b..e1b92a6 100644 --- a/example/lib/pages/map/change_map_type.dart +++ b/example/lib/pages/map/change_map_type.dart @@ -3,10 +3,10 @@ import 'package:amap_map_example/widgets/amap_radio_group.dart'; import 'package:flutter/material.dart'; class ChangeMapTypePage extends StatefulWidget { - ChangeMapTypePage({Key? key}) : super(key: key); + ChangeMapTypePage({super.key}); @override - _PageBodyState createState() => _PageBodyState(); + State createState() => _PageBodyState(); } class _PageBodyState extends State { diff --git a/example/lib/pages/map/custom_map_style.dart b/example/lib/pages/map/custom_map_style.dart index c151255..7debde1 100644 --- a/example/lib/pages/map/custom_map_style.dart +++ b/example/lib/pages/map/custom_map_style.dart @@ -4,16 +4,16 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class CustomMapStylePage extends StatefulWidget { - CustomMapStylePage({Key? key}) : super(key: key); + CustomMapStylePage({super.key}); @override - _CustomMapStyleState createState() => _CustomMapStyleState(); + State createState() => _CustomMapStyleState(); } class _CustomMapStyleState extends State { bool _mapCreated = false; - CustomStyleOptions _customStyleOptions = CustomStyleOptions(false); + final CustomStyleOptions _customStyleOptions = CustomStyleOptions(false); //加载自定义地图样式 void _loadCustomData() async { ByteData styleByteData = await rootBundle.load('assets/style.data'); diff --git a/example/lib/pages/map/limit_map_bounds.dart b/example/lib/pages/map/limit_map_bounds.dart index 28d6963..7f8809a 100644 --- a/example/lib/pages/map/limit_map_bounds.dart +++ b/example/lib/pages/map/limit_map_bounds.dart @@ -3,10 +3,10 @@ import 'package:x_amap_base/x_amap_base.dart'; import 'package:flutter/material.dart'; class LimitMapBoundsPage extends StatefulWidget { - LimitMapBoundsPage({Key? key}) : super(key: key); + LimitMapBoundsPage({super.key}); @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { diff --git a/example/lib/pages/map/map_all_config.dart b/example/lib/pages/map/map_all_config.dart index e9143d2..b8df8bf 100644 --- a/example/lib/pages/map/map_all_config.dart +++ b/example/lib/pages/map/map_all_config.dart @@ -1,5 +1,3 @@ -import 'dart:typed_data'; - import 'package:amap_map/amap_map.dart'; import 'package:amap_map_example/widgets/amap_switch_button.dart'; import 'package:flutter/material.dart'; @@ -54,10 +52,10 @@ class _MapUiBodyState extends State { late AMapController _controller; - CustomStyleOptions _customStyleOptions = CustomStyleOptions(false); + final CustomStyleOptions _customStyleOptions = CustomStyleOptions(false); ///自定义定位小蓝点 - MyLocationStyleOptions _myLocationStyleOptions = + final MyLocationStyleOptions _myLocationStyleOptions = MyLocationStyleOptions(false); @override void initState() { @@ -100,7 +98,7 @@ class _MapUiBodyState extends State { onPoiTouched: _onMapPoiTouched, ); - Widget _mapTypeRadio(String label, MapType radioValue) { + Widget mapTypeRadio(String label, MapType radioValue) { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -118,16 +116,16 @@ class _MapUiBodyState extends State { ); } - final List _mapTypeList = [ - _mapTypeRadio('普通地图', MapType.normal), - _mapTypeRadio('卫星地图', MapType.satellite), - _mapTypeRadio('导航地图', MapType.navi), - _mapTypeRadio('公交地图', MapType.bus), - _mapTypeRadio('黑夜模式', MapType.night), + final List mapTypeList = [ + mapTypeRadio('普通地图', MapType.normal), + mapTypeRadio('卫星地图', MapType.satellite), + mapTypeRadio('导航地图', MapType.navi), + mapTypeRadio('公交地图', MapType.bus), + mapTypeRadio('黑夜模式', MapType.night), ]; //ui控制 - final List _uiOptions = [ + final List uiOptions = [ AMapSwitchButton( label: Text('显示路况'), defaultValue: _trafficEnabled, @@ -233,7 +231,7 @@ class _MapUiBodyState extends State { ), ]; - Widget _mapTypeOptions() { + Widget mapTypeOptions() { return Container( padding: EdgeInsets.all(5), child: Column( @@ -243,14 +241,14 @@ class _MapUiBodyState extends State { Text('地图样式', style: TextStyle(fontWeight: FontWeight.w600)), Container( padding: EdgeInsets.only(left: 10), - child: createGridView(_mapTypeList), + child: createGridView(mapTypeList), ), ], ), ); } - Widget _myLocationStyleContainer() { + Widget myLocationStyleContainer() { return Container( padding: EdgeInsets.all(5), child: Row( @@ -273,7 +271,7 @@ class _MapUiBodyState extends State { ); } - Widget _uiOptionsWidget() { + Widget uiOptionsWidget() { return Container( padding: EdgeInsets.all(5), child: Column( @@ -283,14 +281,14 @@ class _MapUiBodyState extends State { Text('UI操作', style: TextStyle(fontWeight: FontWeight.w600)), Container( padding: EdgeInsets.only(left: 10), - child: createGridView(_uiOptions), + child: createGridView(uiOptions), ), ], ), ); } - Widget _gesturesOptiosWeidget() { + Widget gesturesOptiosWeidget() { return Container( padding: EdgeInsets.all(5), child: Column( @@ -307,13 +305,13 @@ class _MapUiBodyState extends State { ); } - Widget _optionsItem() { + Widget optionsItem() { return Column( children: [ - _mapTypeOptions(), - _myLocationStyleContainer(), - _uiOptionsWidget(), - _gesturesOptiosWeidget(), + mapTypeOptions(), + myLocationStyleContainer(), + uiOptionsWidget(), + gesturesOptiosWeidget(), TextButton( child: const Text('moveCamera到首开'), onPressed: _moveCameraToShoukai, @@ -337,7 +335,7 @@ class _MapUiBodyState extends State { Expanded( child: SingleChildScrollView( child: Container( - child: _optionsItem(), + child: optionsItem(), ), ), ), @@ -366,7 +364,7 @@ class _MapUiBodyState extends State { Widget createGridView(List widgets) { return GridView.count( primary: false, - physics: new NeverScrollableScrollPhysics(), + physics: NeverScrollableScrollPhysics(), //水平子Widget之间间距 crossAxisSpacing: 1.0, //垂直子Widget之间间距 diff --git a/example/lib/pages/map/map_my_location.dart b/example/lib/pages/map/map_my_location.dart index d833da6..3aad658 100644 --- a/example/lib/pages/map/map_my_location.dart +++ b/example/lib/pages/map/map_my_location.dart @@ -3,9 +3,9 @@ import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; class MyLocationPage extends StatefulWidget { - MyLocationPage({Key? key}) : super(key: key); + MyLocationPage({super.key}); @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { diff --git a/example/lib/pages/map/min_max_zoom.dart b/example/lib/pages/map/min_max_zoom.dart index 0dc057c..2669711 100644 --- a/example/lib/pages/map/min_max_zoom.dart +++ b/example/lib/pages/map/min_max_zoom.dart @@ -2,10 +2,10 @@ import 'package:amap_map/amap_map.dart'; import 'package:flutter/material.dart'; class MinMaxZoomDemoPage extends StatefulWidget { - MinMaxZoomDemoPage({Key? key}) : super(key: key); + MinMaxZoomDemoPage({super.key}); @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { diff --git a/example/lib/pages/map/show_map_page.dart b/example/lib/pages/map/show_map_page.dart index 025baf0..d20e27b 100644 --- a/example/lib/pages/map/show_map_page.dart +++ b/example/lib/pages/map/show_map_page.dart @@ -8,7 +8,7 @@ class ShowMapPage extends StatefulWidget { } class _ShowMapPageState extends State { - List _approvalNumberWidget = []; + final List _approvalNumberWidget = []; @override Widget build(BuildContext context) { final AMapWidget map = AMapWidget( diff --git a/example/lib/pages/overlays/custom_info_window.dart b/example/lib/pages/overlays/custom_info_window.dart index 87d43a4..0299bf8 100644 --- a/example/lib/pages/overlays/custom_info_window.dart +++ b/example/lib/pages/overlays/custom_info_window.dart @@ -18,7 +18,7 @@ class CustomInfoWindowDemoPage extends StatefulWidget { class _State extends State { static final LatLng mapCenter = const LatLng(39.909187, 116.397451); - Map _markers = {}; + final Map _markers = {}; BitmapDescriptor? _markerIcon; String? selectedMarkerId; bool showInfoWindow = false; @@ -77,7 +77,7 @@ class _State extends State { } void _removeAll() { - if (_markers.length > 0) { + if (_markers.isNotEmpty) { setState(() { _markers.clear(); selectedMarkerId = null.toString(); @@ -87,7 +87,7 @@ class _State extends State { 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 { 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 { children: [ 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 { } class CustomInfoWindowAdapter extends BaseInfoWindowAdapter { - CustomInfoWindowAdapter(AMapController? controller, this.selectedMarkerId) - : super(controller); + CustomInfoWindowAdapter(super.controller, this.selectedMarkerId); final String? selectedMarkerId; diff --git a/example/lib/pages/overlays/marker_add_after_map.dart b/example/lib/pages/overlays/marker_add_after_map.dart index 3aa001d..a8fa19f 100644 --- a/example/lib/pages/overlays/marker_add_after_map.dart +++ b/example/lib/pages/overlays/marker_add_after_map.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; class MarkerAddAfterMapPage extends StatefulWidget { @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { @@ -14,16 +14,16 @@ class _BodyState extends State { 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 { 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; } //默认背景颜色 diff --git a/example/lib/pages/overlays/marker_add_with_map.dart b/example/lib/pages/overlays/marker_add_with_map.dart index e1fa465..8d0e093 100644 --- a/example/lib/pages/overlays/marker_add_with_map.dart +++ b/example/lib/pages/overlays/marker_add_with_map.dart @@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; class MarkerAddWithMapPage extends StatefulWidget { @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { diff --git a/example/lib/pages/overlays/marker_config.dart b/example/lib/pages/overlays/marker_config.dart index 9b74b98..c516de1 100644 --- a/example/lib/pages/overlays/marker_config.dart +++ b/example/lib/pages/overlays/marker_config.dart @@ -19,7 +19,7 @@ class MarkerConfigDemoPage extends StatefulWidget { class _State extends State { static final LatLng mapCenter = const LatLng(39.909187, 116.397451); - Map _markers = {}; + final Map _markers = {}; BitmapDescriptor? _markerIcon; String? selectedMarkerId; @@ -27,11 +27,11 @@ class _State extends State { 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 { } void _removeAll() { - if (_markers.length > 0) { + if (_markers.isNotEmpty) { setState(() { _markers.clear(); selectedMarkerId = null.toString(); @@ -129,7 +129,7 @@ class _State extends State { 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 { 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 { children: [ TextButton( child: const Text('全部移除'), - onPressed: _markers.length > 0 ? _removeAll : null, + onPressed: _markers.isNotEmpty ? _removeAll : null, ), AMapSwitchButton( label: Text('允许拖动'), diff --git a/example/lib/pages/overlays/marker_custom_icon.dart b/example/lib/pages/overlays/marker_custom_icon.dart index 3033e8e..ba1a2a6 100644 --- a/example/lib/pages/overlays/marker_custom_icon.dart +++ b/example/lib/pages/overlays/marker_custom_icon.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; class MarkerCustomIconPage extends StatefulWidget { @override - _BodyState createState() => _BodyState(); + State createState() => _BodyState(); } class _BodyState extends State { @@ -42,16 +42,16 @@ class _BodyState extends State { 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; } //默认背景颜色 diff --git a/example/lib/pages/overlays/place_polygon.dart b/example/lib/pages/overlays/place_polygon.dart index 8b8511b..51741e0 100644 --- a/example/lib/pages/overlays/place_polygon.dart +++ b/example/lib/pages/overlays/place_polygon.dart @@ -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 { Colors.pink, ]; - Map _polygons = {}; + final Map _polygons = {}; String? selectedPolygonId; void _onMapCreated(AMapController controller) {} diff --git a/example/lib/pages/overlays/place_polyline.dart b/example/lib/pages/overlays/place_polyline.dart index 40b4ddf..9e79c71 100644 --- a/example/lib/pages/overlays/place_polyline.dart +++ b/example/lib/pages/overlays/place_polyline.dart @@ -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 { Colors.green, Colors.pink, ]; - Map _polylines = {}; + final Map _polylines = {}; String? selectedPolylineId; void _onMapCreated(AMapController controller) {} @@ -64,7 +63,7 @@ class _State extends State { } 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 { } void _changeCapType() { - final Polyline? polyline = _polylines[selectedPolylineId]!; + final Polyline? polyline = _polylines[selectedPolylineId]; if (polyline == null) { return; } diff --git a/example/lib/pages/overlays/polyline_geodesic.dart b/example/lib/pages/overlays/polyline_geodesic.dart index e6531c5..e3030f2 100644 --- a/example/lib/pages/overlays/polyline_geodesic.dart +++ b/example/lib/pages/overlays/polyline_geodesic.dart @@ -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 { Colors.green, Colors.pink, ]; - Map _polylines = {}; + final Map _polylines = {}; late String selectedPolylineId; AMapController? _controller; @@ -89,16 +88,16 @@ class _State extends State { 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; } //默认背景颜色 diff --git a/example/lib/pages/overlays/polyline_texture.dart b/example/lib/pages/overlays/polyline_texture.dart index ac346dd..c8a72c1 100644 --- a/example/lib/pages/overlays/polyline_texture.dart +++ b/example/lib/pages/overlays/polyline_texture.dart @@ -13,7 +13,7 @@ class PolylineTextureDemoPage extends StatefulWidget { class _State extends State { _State(); - Map _polylines = {}; + final Map _polylines = {}; late String selectedPolylineId; void _onMapCreated(AMapController controller) {} @@ -76,16 +76,16 @@ class _State extends State { 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; } //默认背景颜色 diff --git a/example/lib/routes.dart b/example/lib/routes.dart index 292bda2..6824d30 100644 --- a/example/lib/routes.dart +++ b/example/lib/routes.dart @@ -23,7 +23,7 @@ class Path { } class RouteConfig { - static List _paths = [ + static final List _paths = [ Path( r'^/([\w-]+)$', (context, match) => DemoPage(slug: match), diff --git a/example/lib/theme.dart b/example/lib/theme.dart deleted file mode 100644 index 74c2074..0000000 --- a/example/lib/theme.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:flutter/material.dart'; - -class DemoThemeData { - static const _lightFillColor = Colors.black; - static const ColorScheme lightColorScheme = ColorScheme( - primary: Color(0xFFB93C5D), - primaryContainer: Color(0xFF117378), - secondary: Color(0xFFEFF3F3), - secondaryContainer: Color(0xFFFAFBFB), - background: Color(0xFFE6EBEB), - surface: Color(0xFFFAFBFB), - onBackground: Colors.white, - error: _lightFillColor, - onError: _lightFillColor, - onPrimary: _lightFillColor, - onSecondary: Color(0xFF322942), - onSurface: Color(0xFF241E30), - brightness: Brightness.light, - ); -} diff --git a/example/lib/widgets/amap_gridview.dart b/example/lib/widgets/amap_gridview.dart index 3b319d8..9172f71 100644 --- a/example/lib/widgets/amap_gridview.dart +++ b/example/lib/widgets/amap_gridview.dart @@ -16,7 +16,7 @@ class AMapGradView extends StatefulWidget { this.childAspectRatio, required this.childrenWidgets}); @override - _GradViewState createState() => _GradViewState(); + State createState() => _GradViewState(); } class _GradViewState extends State { diff --git a/example/lib/widgets/amap_radio_group.dart b/example/lib/widgets/amap_radio_group.dart index 75edac2..5b8b298 100644 --- a/example/lib/widgets/amap_radio_group.dart +++ b/example/lib/widgets/amap_radio_group.dart @@ -14,7 +14,7 @@ class AMapRadioGroup extends StatefulWidget { this.onChanged}); @override - _AMapRadioGroupState createState() => _AMapRadioGroupState(); + State> createState() => _AMapRadioGroupState(); } class _AMapRadioGroupState extends State> { diff --git a/lib/src/amap_widget.dart b/lib/src/amap_widget.dart index 508e308..536bf8a 100644 --- a/lib/src/amap_widget.dart +++ b/lib/src/amap_widget.dart @@ -223,7 +223,7 @@ class _MapState extends State { @override void deactivate() async { super.deactivate(); - print('deactivate AMapWidget}'); + print('deactivate AMapWidget'); } @override diff --git a/lib/src/types/base_overlay.dart b/lib/src/types/base_overlay.dart index 122749b..eb9ded3 100644 --- a/lib/src/types/base_overlay.dart +++ b/lib/src/types/base_overlay.dart @@ -1,27 +1,42 @@ -/// 地图覆盖物基类 +import 'package:flutter/foundation.dart'; + class BaseOverlay { /// overlay id - late String _id; + String _id; String get id => _id; - BaseOverlay() { - _id = hashCode.toString(); + // 初始化 _id,在创建对象时唯一确定 + BaseOverlay() : _id = _generateUniqueId(); + + // 设置复制的 ID,确保拷贝对象时的唯一性或保留性 + void setIdForCopy(String copyId) { + if (copyId.isNotEmpty) { + _id = copyId; + } else { + throw ArgumentError('Invalid ID for copy'); + } } - void setIdForCopy(String copyId) => _id = copyId; - + // 克隆对象,确保子类正确实现 clone 方法 BaseOverlay clone() { throw UnimplementedError( - 'BaseOverlay subClass should implement this methed.'); + 'BaseOverlay subClass should implement this method.'); } + // 将对象转换为 map 表示 Map toMap() { throw UnimplementedError( - 'BaseOverlay subClass should implement this methed.'); + 'BaseOverlay subClass should implement this method.'); + } + + // 生成唯一 ID 的静态方法 + static String _generateUniqueId() { + return '${DateTime.now().millisecondsSinceEpoch}_${UniqueKey()}'; } } +// 序列化覆盖物集合 List>? serializeOverlaySet(Set overlays) { return overlays .map>((BaseOverlay overlay) => overlay.toMap()) diff --git a/lib/src/types/marker.dart b/lib/src/types/marker.dart index 20fe352..0190155 100644 --- a/lib/src/types/marker.dart +++ b/lib/src/types/marker.dart @@ -245,6 +245,17 @@ class Marker extends BaseOverlay { @override int get hashCode => Object.hashAll([ id, + alpha, + anchor, + clickable, + draggable, + icon, + infoWindowEnable, + infoWindow, + position, + rotation, + visible, + zIndex ]); } diff --git a/lib/src/types/polygon.dart b/lib/src/types/polygon.dart index 8b28359..cf6bb13 100644 --- a/lib/src/types/polygon.dart +++ b/lib/src/types/polygon.dart @@ -100,9 +100,8 @@ class Polygon extends BaseOverlay { } @override - int get hashCode => Object.hashAll([ - id, - ]); + int get hashCode => Object.hashAll( + [id, points, strokeWidth, strokeColor, fillColor, visible, joinType]); dynamic _pointsToJson() { final List result = []; diff --git a/lib/src/types/polyline.dart b/lib/src/types/polyline.dart index ed987d1..497b836 100644 --- a/lib/src/types/polyline.dart +++ b/lib/src/types/polyline.dart @@ -188,6 +188,15 @@ class Polyline extends BaseOverlay { @override int get hashCode => Object.hashAll([ id, + points, + width, + visible, + geodesic, + alpha, + dashLineType, + capType, + joinType, + color ]); } diff --git a/pubspec.yaml b/pubspec.yaml index 36b9381..ce1ae98 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: amap_map description: Amap SDK Flutter plugin for integrating AMapSDK in iOS and Android applications. -version: 1.0.11 +version: 1.0.12 homepage: https://github.com/kuloud/amap_map issue_tracker: https://github.com/kuloud/amap_map/issues platforms: