From 19c0c3bae68b3e7284d98cd0e489ab7491ee1fcd Mon Sep 17 00:00:00 2001 From: kuloud Date: Wed, 12 Mar 2025 11:03:18 +0800 Subject: [PATCH] chore: code lint --- CHANGELOG.md | 4 ++ README.md | 16 +++--- analysis_options.yaml | 22 +++++++- .../flutter/map/AMapFlutterMapPlugin.java | 4 -- example/lib/animated_category_item.dart | 3 +- .../pages/interactive/move_camera_demo.dart | 40 +++++++------- example/lib/pages/map/map_all_config.dart | 54 ++++++++++--------- example/lib/pages/map/min_max_zoom.dart | 18 +++---- example/lib/pages/map/multi_map.dart | 4 +- .../pages/overlays/custom_info_window.dart | 34 ++++++------ example/lib/pages/overlays/marker_config.dart | 20 +++---- .../pages/overlays/marker_custom_icon.dart | 8 +-- example/lib/pages/overlays/place_polygon.dart | 16 +++--- .../lib/pages/overlays/place_polyline.dart | 22 ++++---- example/pubspec.yaml | 1 - example/test/amap_tools_test.dart | 20 +++---- lib/src/types/marker.dart | 4 +- lib/src/types/polygon.dart | 4 +- lib/src/types/polyline.dart | 2 +- lib/src/types/ui.dart | 4 +- pubspec.yaml | 4 +- 21 files changed, 164 insertions(+), 140 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b979dec..058d17f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.14 +2025-03-12 +* code lint + ## 1.0.13 2025-03-11 * 升级amap android sdk版本 10.1.200_loc6.4.9_sea9.7.4 | 2025-03-11 diff --git a/README.md b/README.md index 9112724..f1c12d1 100644 --- a/README.md +++ b/README.md @@ -259,16 +259,16 @@ class AMapController { 1. [android] app 的 targetSDKVersion >= 30, 地图页返回闪退 -在里的 AndroidManifest.xml 里的 application 里增加`android:allowNativeHeapPointerTagging="false"` + 在里的 AndroidManifest.xml 里的 application 里增加`android:allowNativeHeapPointerTagging="false"` -```xml - - ... - -``` + ```xml + + ... + + ``` -google 官方说明地址:https://source.android.com/devices/tech/debug/tagged-pointers + google 官方说明地址:https://source.android.com/devices/tech/debug/tagged-pointers 1. 原本本插件拓展设计的思路是把一些不常用的特性功能做成可插拔的 extension,昨天(2024/07/28)考虑了下,觉得有点过度设计了,包括轻量版 SDK 的接入适配,于是决定后续实现做些调整,尽量贴合 SDK API 实现功能。 -1. 如果模拟器运行遇到 `com.amap.api.col.3sl.dl$b.createContext(GlesUtility.java:73)` 闪退,可尝试切换模拟器图像加速模式为`Software`以获得更好的兼容性。(#27) +1. 如果模拟器运行遇到 `com.amap.api.col.3sl.dl$b.createContext(GlesUtility.java:73)` 闪退,可尝试切换模拟器图像加速模式为`Software`以获得更好的兼容性。[Issue #27](https://github.com/kuloud/amap_map/issues/27) diff --git a/analysis_options.yaml b/analysis_options.yaml index ea2c9e9..97772f7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1,21 @@ -include: package:lints/recommended.yaml \ No newline at end of file +include: package:flutter_lints/flutter.yaml + +analyzer: + exclude: + - "**/*.g.dart" + - "**/*.freezed.dart" + errors: + missing_required_param: error + missing_return: error + invalid_null_aware_operator: error + +linter: + rules: + always_specify_types: true + prefer_final_fields: true + prefer_final_in_for_each: true + prefer_const_constructors: true + prefer_const_declarations: true + avoid_print: false + avoid_empty_else: true + sort_child_properties_last: true \ No newline at end of file diff --git a/android/src/main/java/com/amap/flutter/map/AMapFlutterMapPlugin.java b/android/src/main/java/com/amap/flutter/map/AMapFlutterMapPlugin.java index 1ce5f5a..ea73720 100644 --- a/android/src/main/java/com/amap/flutter/map/AMapFlutterMapPlugin.java +++ b/android/src/main/java/com/amap/flutter/map/AMapFlutterMapPlugin.java @@ -1,10 +1,7 @@ package com.amap.flutter.map; -import android.app.Activity; - import androidx.annotation.NonNull; import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleOwner; import com.amap.flutter.map.utils.LogUtil; @@ -12,7 +9,6 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.activity.ActivityAware; import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter; -import io.flutter.plugin.common.PluginRegistry; /** * AmapFlutterMapPlugin diff --git a/example/lib/animated_category_item.dart b/example/lib/animated_category_item.dart index dad6fef..14a6252 100644 --- a/example/lib/animated_category_item.dart +++ b/example/lib/animated_category_item.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; class AnimatedCategoryItem extends StatelessWidget { AnimatedCategoryItem({ + super.key, required double startDelayFraction, required this.controller, required this.child, @@ -27,7 +28,7 @@ class AnimatedCategoryItem extends StatelessWidget { Widget build(BuildContext context) { return AnimatedBuilder( animation: controller, - builder: (context, child) { + builder: (BuildContext context, Widget? child) { return Padding( padding: EdgeInsets.only(top: topPaddingAnimation.value), child: child, diff --git a/example/lib/pages/interactive/move_camera_demo.dart b/example/lib/pages/interactive/move_camera_demo.dart index 010373f..ced0df3 100644 --- a/example/lib/pages/interactive/move_camera_demo.dart +++ b/example/lib/pages/interactive/move_camera_demo.dart @@ -4,7 +4,7 @@ import 'package:amap_map_example/widgets/amap_gridview.dart'; import 'package:flutter/material.dart'; class MoveCameraDemoPage extends StatefulWidget { - MoveCameraDemoPage({super.key}); + const MoveCameraDemoPage({super.key}); @override State createState() => _BodyState(); @@ -29,7 +29,7 @@ class _BodyState extends State { Widget cameraOptions() { return Container( - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, @@ -45,7 +45,7 @@ class _BodyState extends State { } return ConstrainedBox( - constraints: BoxConstraints.expand(), + constraints: const BoxConstraints.expand(), child: Column( children: [ ConstrainedBox( @@ -54,7 +54,7 @@ class _BodyState extends State { minHeight: MediaQuery.of(context).size.height * 0.7), child: Stack( children: [ - Container( + SizedBox( height: MediaQuery.of(context).size.height * 0.7, width: MediaQuery.of(context).size.width, child: amap, @@ -66,28 +66,28 @@ class _BodyState extends State { mainAxisSize: MainAxisSize.min, children: [ InkResponse( + onTap: _zoomIn, child: Container( - child: Icon( + width: 40, + height: 40, + color: Colors.blue, + child: const Icon( Icons.add, color: Colors.white, ), - width: 40, - height: 40, - color: Colors.blue, ), - onTap: _zoomIn, ), InkResponse( + onTap: _zoomOut, child: Container( - child: Icon( + color: Colors.blue, + width: 40, + height: 40, + child: const Icon( Icons.remove, color: Colors.white, ), - color: Colors.blue, - width: 40, - height: 40, ), - onTap: _zoomOut, ), ], ), @@ -103,14 +103,14 @@ class _BodyState extends State { ? Container( width: MediaQuery.of(context).size.width, color: Colors.grey, - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), alignment: Alignment.centerLeft, child: Text( _currentZoom!, - style: TextStyle(color: Colors.white), + style: const TextStyle(color: Colors.white), ), ) - : SizedBox(), + : const SizedBox(), Container( child: cameraOptions(), ), @@ -141,7 +141,7 @@ class _BodyState extends State { void _changeCameraPosition() { _mapController?.moveCamera( CameraUpdate.newCameraPosition( - CameraPosition( + const CameraPosition( //中心点 target: LatLng(31.230378, 121.473658), //缩放级别 @@ -184,8 +184,8 @@ class _BodyState extends State { _mapController?.moveCamera( CameraUpdate.newLatLngBounds( LatLngBounds( - southwest: LatLng(33.789925, 104.838326), - northeast: LatLng(38.740688, 114.647472)), + southwest: const LatLng(33.789925, 104.838326), + northeast: const LatLng(38.740688, 114.647472)), 15.0), animated: true, ); diff --git a/example/lib/pages/map/map_all_config.dart b/example/lib/pages/map/map_all_config.dart index b8df8bf..5849e7c 100644 --- a/example/lib/pages/map/map_all_config.dart +++ b/example/lib/pages/map/map_all_config.dart @@ -6,13 +6,15 @@ import 'package:flutter/services.dart'; import 'package:x_amap_base/x_amap_base.dart'; class AllMapConfigDemoPage extends StatefulWidget { + const AllMapConfigDemoPage({super.key}); + @override State createState() => _MapUiBodyState(); } class _MapUiBodyState extends State { //默认显示在北京天安门 - static final CameraPosition _kInitialPosition = const CameraPosition( + static const CameraPosition _kInitialPosition = CameraPosition( target: LatLng(39.909187, 116.397451), zoom: 10.0, ); @@ -127,7 +129,7 @@ class _MapUiBodyState extends State { //ui控制 final List uiOptions = [ AMapSwitchButton( - label: Text('显示路况'), + label: const Text('显示路况'), defaultValue: _trafficEnabled, onSwitchChanged: (value) => { setState(() { @@ -136,7 +138,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('显示3D建筑物'), + label: const Text('显示3D建筑物'), defaultValue: _buildingsEnabled, onSwitchChanged: (value) => { setState(() { @@ -145,7 +147,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('显示指南针'), + label: const Text('显示指南针'), defaultValue: _compassEnabled, onSwitchChanged: (value) => { setState(() { @@ -154,7 +156,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('显示地图文字'), + label: const Text('显示地图文字'), defaultValue: _labelsEnabled, onSwitchChanged: (value) => { setState(() { @@ -163,7 +165,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('显示比例尺'), + label: const Text('显示比例尺'), defaultValue: _scaleEnabled, onSwitchChanged: (value) => { setState(() { @@ -172,7 +174,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('点击Poi'), + label: const Text('点击Poi'), defaultValue: _touchPoiEnabled, onSwitchChanged: (value) => { setState(() { @@ -181,7 +183,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('自定义地图'), + label: const Text('自定义地图'), defaultValue: _customStyleOptions.enabled, onSwitchChanged: (value) => { setState(() { @@ -194,7 +196,7 @@ class _MapUiBodyState extends State { //手势开关 final List gesturesOptions = [ AMapSwitchButton( - label: Text('旋转'), + label: const Text('旋转'), defaultValue: _rotateGesturesEnabled, onSwitchChanged: (value) => { setState(() { @@ -203,7 +205,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('滑动'), + label: const Text('滑动'), defaultValue: _scrollGesturesEnabled, onSwitchChanged: (value) => { setState(() { @@ -212,7 +214,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('倾斜'), + label: const Text('倾斜'), defaultValue: _tiltGesturesEnabled, onSwitchChanged: (value) => { setState(() { @@ -221,7 +223,7 @@ class _MapUiBodyState extends State { }, ), AMapSwitchButton( - label: Text('缩放'), + label: const Text('缩放'), defaultValue: _zoomGesturesEnabled, onSwitchChanged: (value) => { setState(() { @@ -233,14 +235,14 @@ class _MapUiBodyState extends State { Widget mapTypeOptions() { return Container( - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - Text('地图样式', style: TextStyle(fontWeight: FontWeight.w600)), + const Text('地图样式', style: TextStyle(fontWeight: FontWeight.w600)), Container( - padding: EdgeInsets.only(left: 10), + padding: const EdgeInsets.only(left: 10), child: createGridView(mapTypeList), ), ], @@ -250,15 +252,15 @@ class _MapUiBodyState extends State { Widget myLocationStyleContainer() { return Container( - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), child: Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ // Text('定位小蓝点', style: TextStyle(fontWeight: FontWeight.w600)), AMapSwitchButton( - label: - Text('定位小蓝点', style: TextStyle(fontWeight: FontWeight.w600)), + label: const Text('定位小蓝点', + style: TextStyle(fontWeight: FontWeight.w600)), defaultValue: _myLocationStyleOptions.enabled, onSwitchChanged: (value) => { setState(() { @@ -273,14 +275,14 @@ class _MapUiBodyState extends State { Widget uiOptionsWidget() { return Container( - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - Text('UI操作', style: TextStyle(fontWeight: FontWeight.w600)), + const Text('UI操作', style: TextStyle(fontWeight: FontWeight.w600)), Container( - padding: EdgeInsets.only(left: 10), + padding: const EdgeInsets.only(left: 10), child: createGridView(uiOptions), ), ], @@ -290,14 +292,14 @@ class _MapUiBodyState extends State { Widget gesturesOptiosWeidget() { return Container( - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - Text('手势控制', style: TextStyle(fontWeight: FontWeight.w600)), + const Text('手势控制', style: TextStyle(fontWeight: FontWeight.w600)), Container( - padding: EdgeInsets.only(left: 10), + padding: const EdgeInsets.only(left: 10), child: createGridView(gesturesOptions), ), ], @@ -364,7 +366,7 @@ class _MapUiBodyState extends State { Widget createGridView(List widgets) { return GridView.count( primary: false, - physics: NeverScrollableScrollPhysics(), + physics: const NeverScrollableScrollPhysics(), //水平子Widget之间间距 crossAxisSpacing: 1.0, //垂直子Widget之间间距 @@ -379,7 +381,7 @@ class _MapUiBodyState extends State { //移动地图中心点到首开广场 void _moveCameraToShoukai() { - _controller.moveCamera(CameraUpdate.newCameraPosition(CameraPosition( + _controller.moveCamera(CameraUpdate.newCameraPosition(const CameraPosition( target: LatLng(39.993306, 116.473004), zoom: 18, tilt: 30, diff --git a/example/lib/pages/map/min_max_zoom.dart b/example/lib/pages/map/min_max_zoom.dart index 2669711..969b1db 100644 --- a/example/lib/pages/map/min_max_zoom.dart +++ b/example/lib/pages/map/min_max_zoom.dart @@ -2,7 +2,7 @@ import 'package:amap_map/amap_map.dart'; import 'package:flutter/material.dart'; class MinMaxZoomDemoPage extends StatefulWidget { - MinMaxZoomDemoPage({super.key}); + const MinMaxZoomDemoPage({super.key}); @override State createState() => _BodyState(); @@ -22,7 +22,7 @@ class _BodyState extends State { minMaxZoomPreference: MinMaxZoomPreference(_minZoom, _maxZoom), ); return ConstrainedBox( - constraints: BoxConstraints.expand(), + constraints: const BoxConstraints.expand(), child: Stack( children: [ Container( @@ -40,24 +40,24 @@ class _BodyState extends State { Container( width: MediaQuery.of(context).size.width, color: Colors.grey, - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), alignment: Alignment.centerLeft, child: Text( '当前限制的最小最大缩放级别是:[$_minZoom, $_maxZoom]', - style: TextStyle(color: Colors.blue), + style: const TextStyle(color: Colors.blue), ), ), _currentZoom != null ? Container( width: MediaQuery.of(context).size.width, color: Colors.grey, - padding: EdgeInsets.all(5), + padding: const EdgeInsets.all(5), alignment: Alignment.centerLeft, child: Text( _currentZoom!, - style: TextStyle(color: Colors.white), + style: const TextStyle(color: Colors.white), )) - : SizedBox(), + : const SizedBox(), ], ), ), @@ -69,7 +69,7 @@ class _BodyState extends State { children: [ InkResponse( child: Container( - child: Icon( + child: const Icon( Icons.add, color: Colors.white, ), @@ -81,7 +81,7 @@ class _BodyState extends State { ), InkResponse( child: Container( - child: Icon( + child: const Icon( Icons.remove, color: Colors.white, ), diff --git a/example/lib/pages/map/multi_map.dart b/example/lib/pages/map/multi_map.dart index 636e8ee..2ce55fb 100644 --- a/example/lib/pages/map/multi_map.dart +++ b/example/lib/pages/map/multi_map.dart @@ -3,7 +3,7 @@ import 'package:x_amap_base/x_amap_base.dart'; import 'package:flutter/material.dart'; class MultiMapDemoPage extends StatefulWidget { - const MultiMapDemoPage(); + const MultiMapDemoPage({super.key}); @override State createState() => _MultiMapDemoState(); } @@ -14,7 +14,7 @@ class _MultiMapDemoState extends State { return Container( height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, - child: Column( + child: const Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ diff --git a/example/lib/pages/overlays/custom_info_window.dart b/example/lib/pages/overlays/custom_info_window.dart index 0299bf8..b7fa65d 100644 --- a/example/lib/pages/overlays/custom_info_window.dart +++ b/example/lib/pages/overlays/custom_info_window.dart @@ -39,8 +39,8 @@ class _State extends State { position: markPostion, icon: _markerIcon!, infoWindow: InfoWindow(title: '第 $markerCount 个Marker'), - onTap: (markerId) => _onMarkerTapped(markerId), - onDragEnd: (markerId, endPosition) => + onTap: (String markerId) => _onMarkerTapped(markerId), + onDragEnd: (String markerId, LatLng endPosition) => _onMarkerDragEnd(markerId, endPosition), ); @@ -196,7 +196,7 @@ class _State extends State { child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ + children: [ Container( height: MediaQuery.of(context).size.height * 0.6, width: MediaQuery.of(context).size.width, @@ -212,64 +212,64 @@ class _State extends State { Column( children: [ TextButton( - child: const Text('添加'), onPressed: _add, + child: const Text('添加'), ), TextButton( - child: const Text('移除'), onPressed: (selectedMarkerId == null) ? null : _remove, + child: const Text('移除'), ), TextButton( - child: const Text('更新InfoWidow'), onPressed: (selectedMarkerId == null) ? null : _changeInfo, + child: const Text('更新InfoWidow'), ), TextButton( - child: const Text('修改锚点'), onPressed: (selectedMarkerId == null) ? null : _changeAnchor, + child: const Text('修改锚点'), ), TextButton( - child: const Text('修改透明度'), onPressed: (selectedMarkerId == null) ? null : _changeAlpha, + child: const Text('修改透明度'), ), ], ), Column( children: [ TextButton( - child: const Text('全部移除'), onPressed: _markers.isNotEmpty ? _removeAll : null, + child: const Text('全部移除'), ), AMapSwitchButton( - label: Text('允许拖动'), + label: const Text('允许拖动'), onSwitchChanged: (selectedMarkerId == null) ? null : _toggleDraggable, defaultValue: false, ), AMapSwitchButton( - label: Text('显示'), + label: const Text('显示'), onSwitchChanged: (selectedMarkerId == null) ? null : _toggleVisible, defaultValue: true, ), TextButton( - child: const Text('修改坐标'), onPressed: (selectedMarkerId == null) ? null : _changePosition, + child: const Text('修改坐标'), ), TextButton( - child: const Text('修改旋转角度'), onPressed: (selectedMarkerId == null) ? null : _changeRotation, + child: const Text('修改旋转角度'), ), ], ), @@ -300,8 +300,8 @@ class CustomInfoWindowAdapter extends BaseInfoWindowAdapter { decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8.0), - boxShadow: [ - BoxShadow( + boxShadow: [ + const BoxShadow( color: Colors.black26, blurRadius: 4.0, spreadRadius: 2.0, @@ -310,10 +310,10 @@ class CustomInfoWindowAdapter extends BaseInfoWindowAdapter { ), child: Column( mainAxisSize: MainAxisSize.min, - children: [ + children: [ Text( marker.infoWindow.title ?? 'No Title', - style: TextStyle(fontWeight: FontWeight.bold), + style: const TextStyle(fontWeight: FontWeight.bold), ), Text( marker.infoWindow.snippet ?? 'No Snippet', diff --git a/example/lib/pages/overlays/marker_config.dart b/example/lib/pages/overlays/marker_config.dart index c516de1..3764363 100644 --- a/example/lib/pages/overlays/marker_config.dart +++ b/example/lib/pages/overlays/marker_config.dart @@ -266,64 +266,64 @@ class _State extends State { Column( children: [ TextButton( - child: const Text('添加'), onPressed: _add, + child: const Text('添加'), ), TextButton( - child: const Text('移除'), onPressed: (selectedMarkerId == null) ? null : _remove, + child: const Text('移除'), ), TextButton( - child: const Text('更新InfoWidow'), onPressed: (selectedMarkerId == null) ? null : _changeInfo, + child: const Text('更新InfoWidow'), ), TextButton( - child: const Text('修改锚点'), onPressed: (selectedMarkerId == null) ? null : _changeAnchor, + child: const Text('修改锚点'), ), TextButton( - child: const Text('修改透明度'), onPressed: (selectedMarkerId == null) ? null : _changeAlpha, + child: const Text('修改透明度'), ), ], ), Column( children: [ TextButton( - child: const Text('全部移除'), onPressed: _markers.isNotEmpty ? _removeAll : null, + child: const Text('全部移除'), ), AMapSwitchButton( - label: Text('允许拖动'), + label: const Text('允许拖动'), onSwitchChanged: (selectedMarkerId == null) ? null : _toggleDraggable, defaultValue: false, ), AMapSwitchButton( - label: Text('显示'), + label: const Text('显示'), onSwitchChanged: (selectedMarkerId == null) ? null : _toggleVisible, defaultValue: true, ), TextButton( - child: const Text('修改坐标'), onPressed: (selectedMarkerId == null) ? null : _changePosition, + child: const Text('修改坐标'), ), TextButton( - child: const Text('修改旋转角度'), onPressed: (selectedMarkerId == null) ? null : _changeRotation, + child: const Text('修改旋转角度'), ), ], ), diff --git a/example/lib/pages/overlays/marker_custom_icon.dart b/example/lib/pages/overlays/marker_custom_icon.dart index ba1a2a6..4df831f 100644 --- a/example/lib/pages/overlays/marker_custom_icon.dart +++ b/example/lib/pages/overlays/marker_custom_icon.dart @@ -3,17 +3,19 @@ import 'package:x_amap_base/x_amap_base.dart'; import 'package:flutter/material.dart'; class MarkerCustomIconPage extends StatefulWidget { + const MarkerCustomIconPage({super.key}); + @override State createState() => _BodyState(); } class _BodyState extends State { - static final LatLng markerPosition = const LatLng(39.909187, 116.397451); + static const LatLng markerPosition = LatLng(39.909187, 116.397451); final Map _initMarkerMap = {}; String? _currentMarkerId; bool _hasInitMarker = false; - static final String _startIconPath = 'assets/start.png'; - static final String _endIconPath = 'assets/end.png'; + static const String _startIconPath = 'assets/start.png'; + static const String _endIconPath = 'assets/end.png'; String _iconPath = _startIconPath; void _initMarker(BuildContext context) async { if (_hasInitMarker) { diff --git a/example/lib/pages/overlays/place_polygon.dart b/example/lib/pages/overlays/place_polygon.dart index 51741e0..05cd628 100644 --- a/example/lib/pages/overlays/place_polygon.dart +++ b/example/lib/pages/overlays/place_polygon.dart @@ -110,7 +110,7 @@ class _State extends State { List currentPoints = polygon.points; List newPoints = []; newPoints.addAll(currentPoints); - newPoints.add(LatLng(39.828809, 116.360364)); + newPoints.add(const LatLng(39.828809, 116.360364)); setState(() { _polygons[selectedPolygonId!] = polygon.copyWith( @@ -133,7 +133,7 @@ class _State extends State { Widget build(BuildContext context) { final AMapWidget map = AMapWidget( initialCameraPosition: - CameraPosition(target: LatLng(39.828809, 116.360364), zoom: 13), + const CameraPosition(target: LatLng(39.828809, 116.360364), zoom: 13), onMapCreated: _onMapCreated, polygons: Set.of(_polygons.values), ); @@ -159,42 +159,42 @@ class _State extends State { Column( children: [ TextButton( - child: const Text('添加'), onPressed: _add, + child: const Text('添加'), ), TextButton( - child: const Text('删除'), onPressed: (selectedPolygonId == null) ? null : _remove, + child: const Text('删除'), ), TextButton( - child: const Text('修改边框宽度'), onPressed: (selectedPolygonId == null) ? null : _changeStrokeWidth, + child: const Text('修改边框宽度'), ), ], ), Column( children: [ TextButton( - child: const Text('修改边框和填充色'), onPressed: (selectedPolygonId == null) ? null : _changeColors, + child: const Text('修改边框和填充色'), ), AMapSwitchButton( - label: Text('显示'), + label: const Text('显示'), onSwitchChanged: (selectedPolygonId == null) ? null : _toggleVisible, defaultValue: true, ), TextButton( - child: const Text('修改坐标'), onPressed: (selectedPolygonId == null) ? null : _changePoints, + child: const Text('修改坐标'), ), ], ), diff --git a/example/lib/pages/overlays/place_polyline.dart b/example/lib/pages/overlays/place_polyline.dart index 9e79c71..7a28ec1 100644 --- a/example/lib/pages/overlays/place_polyline.dart +++ b/example/lib/pages/overlays/place_polyline.dart @@ -171,7 +171,7 @@ class _State extends State { List currentPoints = polyline.points; List newPoints = []; newPoints.addAll(currentPoints); - newPoints.add(LatLng(39.835347, 116.34575)); + newPoints.add(const LatLng(39.835347, 116.34575)); setState(() { _polylines[selectedPolylineId!] = polyline.copyWith( @@ -218,28 +218,28 @@ class _State extends State { Column( children: [ TextButton( - child: const Text('添加'), onPressed: _add, + child: const Text('添加'), ), TextButton( - child: const Text('删除'), onPressed: (selectedPolylineId == null) ? null : _remove, + child: const Text('删除'), ), TextButton( - child: const Text('修改线宽'), onPressed: (selectedPolylineId == null) ? null : _changeWidth, + child: const Text('修改线宽'), ), TextButton( - child: const Text('修改透明度'), onPressed: (selectedPolylineId == null) ? null : _changeAlpha, + child: const Text('修改透明度'), ), AMapSwitchButton( - label: Text('显示'), + label: const Text('显示'), onSwitchChanged: (selectedPolylineId == null) ? null : _toggleVisible, @@ -250,34 +250,34 @@ class _State extends State { Column( children: [ TextButton( - child: const Text('修改颜色'), onPressed: (selectedPolylineId == null) ? null : _changeColor, + child: const Text('修改颜色'), ), TextButton( - child: const Text('修改线头样式'), onPressed: (selectedPolylineId == null) ? null : _changeCapType, + child: const Text('修改线头样式'), ), TextButton( - child: const Text('修改连接样式'), onPressed: (selectedPolylineId == null) ? null : _changeJointType, + child: const Text('修改连接样式'), ), TextButton( - child: const Text('修改虚线类型'), onPressed: (selectedPolylineId == null) ? null : _changeDashLineType, + child: const Text('修改虚线类型'), ), TextButton( - child: const Text('修改坐标'), onPressed: (selectedPolylineId == null) ? null : _changePoints, + child: const Text('修改坐标'), ), ], ), diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c3d971a..3bfc05f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -13,7 +13,6 @@ dependencies: sdk: flutter permission_handler: ^11.3.1 - flutter_plugin_android_lifecycle: ^2.0.21 amap_map: path: ../ diff --git a/example/test/amap_tools_test.dart b/example/test/amap_tools_test.dart index be2ab71..ab4f08d 100644 --- a/example/test/amap_tools_test.dart +++ b/example/test/amap_tools_test.dart @@ -3,36 +3,36 @@ import 'package:x_amap_base/x_amap_base.dart'; void main() { test('Distance between two different point', () { - LatLng p1 = LatLng(1, 1); - LatLng p2 = LatLng(2, 2); + LatLng p1 = const LatLng(1, 1); + LatLng p2 = const LatLng(2, 2); double distance = AMapTools.distanceBetween(p1, p2); expect(distance, 157401.56104583555); }); test('Distance between two same point', () { - LatLng p1 = LatLng(1, 1); - LatLng p2 = LatLng(1, 1); + LatLng p1 = const LatLng(1, 1); + LatLng p2 = const LatLng(1, 1); double distance = AMapTools.distanceBetween(p1, p2); expect(distance, 0); }); test('Distance between two different point with equal lat', () { - LatLng p1 = LatLng(1, 1); - LatLng p2 = LatLng(1, 2); + LatLng p1 = const LatLng(1, 1); + LatLng p2 = const LatLng(1, 2); double distance = AMapTools.distanceBetween(p1, p2); expect(distance, 111302.53586533663); }); test('Distance between two different point with equal lng', () { - LatLng p1 = LatLng(1, 1); - LatLng p2 = LatLng(2, 1); + LatLng p1 = const LatLng(1, 1); + LatLng p2 = const LatLng(2, 1); double distance = AMapTools.distanceBetween(p1, p2); expect(distance, 111319.49079327357); }); test('Distance between two different point with close point', () { - LatLng p1 = LatLng(39.938212, 116.455139); - LatLng p2 = LatLng(39.987656, 116.265605); + LatLng p1 = const LatLng(39.938212, 116.455139); + LatLng p2 = const LatLng(39.987656, 116.265605); double distance = AMapTools.distanceBetween(p1, p2); expect(distance, 17082.425889709597); }); diff --git a/lib/src/types/marker.dart b/lib/src/types/marker.dart index 0190155..ffa1f5e 100644 --- a/lib/src/types/marker.dart +++ b/lib/src/types/marker.dart @@ -96,12 +96,12 @@ class Marker extends BaseOverlay { (alpha != null ? (alpha < 0 ? 0 : (alpha > 1 ? 1 : alpha)) : alpha), // ignore: unnecessary_null_comparison anchor = (anchor == null - ? Offset(0.5, 1.0) + ? const Offset(0.5, 1.0) : ((anchor.dx < 0 || anchor.dx > 1 || anchor.dy < 0 || anchor.dy > 1) - ? Offset(0.5, 1.0) + ? const Offset(0.5, 1.0) : anchor)), super(); diff --git a/lib/src/types/polygon.dart b/lib/src/types/polygon.dart index cf6bb13..65bf88f 100644 --- a/lib/src/types/polygon.dart +++ b/lib/src/types/polygon.dart @@ -77,8 +77,8 @@ class Polygon extends BaseOverlay { addIfPresent('id', id); json['points'] = _pointsToJson(); addIfPresent('strokeWidth', strokeWidth); - addIfPresent('strokeColor', strokeColor.value); - addIfPresent('fillColor', fillColor.value); + addIfPresent('strokeColor', strokeColor.toARGB32()); + addIfPresent('fillColor', fillColor.toARGB32()); addIfPresent('visible', visible); addIfPresent('joinType', joinType.index); return json; diff --git a/lib/src/types/polyline.dart b/lib/src/types/polyline.dart index 497b836..89abb92 100644 --- a/lib/src/types/polyline.dart +++ b/lib/src/types/polyline.dart @@ -155,7 +155,7 @@ class Polyline extends BaseOverlay { addIfPresent('capType', capType.index); addIfPresent('joinType', joinType.index); addIfPresent('customTexture', customTexture?.toMap()); - addIfPresent('color', color.value); + addIfPresent('color', color.toARGB32()); return json; } diff --git a/lib/src/types/ui.dart b/lib/src/types/ui.dart index 48baf40..128da80 100644 --- a/lib/src/types/ui.dart +++ b/lib/src/types/ui.dart @@ -167,8 +167,8 @@ class MyLocationStyleOptions { } addIfPresent('enabled', enabled); - addIfPresent('circleFillColor', circleFillColor?.value); - addIfPresent('circleStrokeColor', circleStrokeColor?.value); + addIfPresent('circleFillColor', circleFillColor?.toARGB32()); + addIfPresent('circleStrokeColor', circleStrokeColor?.toARGB32()); addIfPresent('circleStrokeWidth', circleStrokeWidth); addIfPresent('icon', icon?.toMap()); return json; diff --git a/pubspec.yaml b/pubspec.yaml index 83216f9..d9a4482 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.13 +version: 1.0.14 homepage: https://github.com/kuloud/amap_map issue_tracker: https://github.com/kuloud/amap_map/issues platforms: @@ -26,9 +26,9 @@ dependencies: x_common: ^1.0.4 dev_dependencies: + flutter_lints: ^5.0.0 flutter_test: sdk: flutter - lints: ^5.1.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec