Compare commits

...

6 Commits

Author SHA1 Message Date
d4d248d714 Merge branch 'main' of https://github.com/kuloud/amap_map
# Conflicts:
#	android/build.gradle
#	pubspec.yaml
2025-03-18 08:21:02 +08:00
19c0c3bae6 chore: code lint 2025-03-12 11:03:18 +08:00
7cd7360eb8 doc: update readme 2025-03-12 10:18:04 +08:00
c11bc05d01 doc: 更新changelog文档 2025-03-12 00:29:59 +08:00
c66b8e1ebd release: 1.0.13 2025-03-12 00:01:15 +08:00
d08a83557d feat: update amap sdk version 2025-03-11 21:22:56 +08:00
31 changed files with 229 additions and 190 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ build/
**/pubspec.lock **/pubspec.lock
.settings/ .settings/
.project .project
**.cxx

View File

@ -1,3 +1,15 @@
## 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
* 升级amap iOS sdk版本 10.1.200 | 2024-12-26
* 修复问题android 构建异常,过期接口 io.flutter.view.FlutterMain 替换
* 修复问题android 构建异常,过期接口 PluginRegistry.Registrar 替换
## 1.0.12 ## 1.0.12
2024-08-26 2024-08-26
* code lint * code lint

View File

@ -6,7 +6,7 @@
| | Android | iOS | | | Android | iOS |
| ----------- | -------------------------- | -------- | | ----------- | -------------------------- | -------- |
| **AMapSDK** | 10.0.800_loc6.4.5_sea9.7.2 | 10.0.900 | | **AMapSDK** | 10.1.200_loc6.4.9_sea9.7.4 | 10.1.200 |
| **Support** | SDK 16+ | 12.0+ | | **Support** | SDK 16+ | 12.0+ |
本插件基于 amap_flutter_map 3.0.0 进行二开的原因: 本插件基于 amap_flutter_map 3.0.0 进行二开的原因:
@ -259,14 +259,16 @@ class AMapController {
1. [android] app 的 targetSDKVersion >= 30, 地图页返回闪退 1. [android] app 的 targetSDKVersion >= 30, 地图页返回闪退
在里的 AndroidManifest.xml 里的 application 里增加`android:allowNativeHeapPointerTagging="false"` 在里的 AndroidManifest.xml 里的 application 里增加`android:allowNativeHeapPointerTagging="false"`
```xml ```xml
<application android:allowNativeHeapPointerTagging="false"> <application android:allowNativeHeapPointerTagging="false">
... ...
</application> </application>
``` ```
google 官方说明地址https://source.android.com/devices/tech/debug/tagged-pointers google 官方说明地址https://source.android.com/devices/tech/debug/tagged-pointers
2. 原本本插件拓展设计的思路是把一些不常用的特性功能做成可插拔的 extension昨天2024/07/28考虑了下觉得有点过度设计了包括轻量版 SDK 的接入适配,于是决定后续实现做些调整,尽量贴合 SDK API 实现功能。 1. 原本本插件拓展设计的思路是把一些不常用的特性功能做成可插拔的 extension昨天2024/07/28考虑了下觉得有点过度设计了包括轻量版 SDK 的接入适配,于是决定后续实现做些调整,尽量贴合 SDK API 实现功能。
1. 如果模拟器运行遇到 `com.amap.api.col.3sl.dl$b.createContext(GlesUtility.java:73)` 闪退,可尝试切换模拟器图像加速模式为`Software`以获得更好的兼容性。[Issue #27](https://github.com/kuloud/amap_map/issues/27)

View File

@ -1 +1,21 @@
include: package:lints/recommended.yaml 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

View File

@ -8,7 +8,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.3' classpath 'com.android.tools.build:gradle:3.5.4'
} }
} }
@ -22,10 +22,8 @@ rootProject.allprojects {
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
android { android {
if (project.android.hasProperty("namespace")) { namespace = "com.amap.flutter.map"
namespace = "com.amap.flutter.map" compileSdkVersion 35
}
compileSdkVersion 34
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
@ -36,8 +34,7 @@ android {
} }
dependencies { dependencies {
// implementation 'com.amap.api:3dmap-location-search:10.0.800_loc6.4.5_sea9.7.2' implementation 'com.amap.api:3dmap-location-search:10.1.200_loc6.4.9_sea9.7.4'
implementation 'com.amap.api:navi-3dmap:latest.integration' implementation 'androidx.annotation:annotation:1.9.1'
implementation 'androidx.annotation:annotation:1.8.1'
} }

View File

@ -1,10 +1,7 @@
package com.amap.flutter.map; package com.amap.flutter.map;
import android.app.Activity;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import com.amap.flutter.map.utils.LogUtil; 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.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter; import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter;
import io.flutter.plugin.common.PluginRegistry;
/** /**
* AmapFlutterMapPlugin * AmapFlutterMapPlugin
@ -23,40 +19,17 @@ public class AMapFlutterMapPlugin implements
private static final String CLASS_NAME = "AMapFlutterMapPlugin"; private static final String CLASS_NAME = "AMapFlutterMapPlugin";
private static final String VIEW_TYPE = "com.amap.flutter.map"; private static final String VIEW_TYPE = "com.amap.flutter.map";
private Lifecycle lifecycle; private Lifecycle lifecycle;
private FlutterPluginBinding pluginBinding;
public AMapFlutterMapPlugin() { public AMapFlutterMapPlugin() {
} }
public static void registerWith(PluginRegistry.Registrar registrar) {
LogUtil.i(CLASS_NAME, "registerWith=====>");
final Activity activity = registrar.activity();
if (activity == null) {
LogUtil.w(CLASS_NAME, "activity is null!!!");
return;
}
if (activity instanceof LifecycleOwner) {
registrar
.platformViewRegistry()
.registerViewFactory(
VIEW_TYPE,
new AMapPlatformViewFactory(
registrar.messenger(),
() -> ((LifecycleOwner) activity).getLifecycle()));
} else {
registrar
.platformViewRegistry()
.registerViewFactory(
VIEW_TYPE,
new AMapPlatformViewFactory(registrar.messenger(), new ProxyLifecycleProvider(activity)));
}
}
// FlutterPlugin // FlutterPlugin
@Override @Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
LogUtil.i(CLASS_NAME, "onAttachedToEngine==>"); LogUtil.i(CLASS_NAME, "onAttachedToEngine==>");
this.pluginBinding = binding;
binding binding
.getPlatformViewRegistry() .getPlatformViewRegistry()
.registerViewFactory( .registerViewFactory(
@ -78,6 +51,13 @@ public class AMapFlutterMapPlugin implements
public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) { public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
LogUtil.i(CLASS_NAME, "onAttachedToActivity==>"); LogUtil.i(CLASS_NAME, "onAttachedToActivity==>");
lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding); lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding);
pluginBinding.getPlatformViewRegistry().registerViewFactory(
VIEW_TYPE,
new AMapPlatformViewFactory(
pluginBinding.getBinaryMessenger(),
() -> lifecycle
)
);
} }
@Override @Override

View File

@ -30,7 +30,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import io.flutter.view.FlutterMain; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.loader.FlutterLoader;
/** /**
* @author whm * @author whm
@ -44,6 +45,15 @@ public class ConvertUtil {
private static final int[] LocationTypeMap = new int[]{MyLocationStyle.LOCATION_TYPE_SHOW, MyLocationStyle.LOCATION_TYPE_FOLLOW, MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE}; private static final int[] LocationTypeMap = new int[]{MyLocationStyle.LOCATION_TYPE_SHOW, MyLocationStyle.LOCATION_TYPE_FOLLOW, MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE};
public static float density; public static float density;
private static String apiKey; private static String apiKey;
private static FlutterLoader flutterLoader; // For asset loading
public static void initialize(Context context) {
flutterLoader = new FlutterLoader();
if (!flutterLoader.initialized()) {
flutterLoader.startInitialization(context);
flutterLoader.ensureInitializationComplete(context, null);
}
}
public static void setPrivacyStatement(Context context, Object object) { public static void setPrivacyStatement(Context context, Object object) {
if (null == object) { if (null == object) {
@ -396,15 +406,15 @@ public class ConvertUtil {
case "fromAsset": case "fromAsset":
if (data.size() == 2) { if (data.size() == 2) {
return BitmapDescriptorFactory.fromAsset( return BitmapDescriptorFactory.fromAsset(
FlutterMain.getLookupKeyForAsset(toString(data.get(1)))); flutterLoader.getLookupKeyForAsset(toString(data.get(1))));
} else { } else {
return BitmapDescriptorFactory.fromAsset( return BitmapDescriptorFactory.fromAsset(
FlutterMain.getLookupKeyForAsset(toString(data.get(1)), toString(data.get(2)))); flutterLoader.getLookupKeyForAsset(toString(data.get(1)), toString(data.get(2))));
} }
case "fromAssetImage": case "fromAssetImage":
if (data.size() == 3) { if (data.size() == 3) {
return BitmapDescriptorFactory.fromAsset( return BitmapDescriptorFactory.fromAsset(
FlutterMain.getLookupKeyForAsset(toString(data.get(1)))); flutterLoader.getLookupKeyForAsset(toString(data.get(1))));
} else { } else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"'fromAssetImage' Expected exactly 3 arguments, got: " + data.size()); "'fromAssetImage' Expected exactly 3 arguments, got: " + data.size());

View File

@ -26,7 +26,8 @@ if (flutterVersionName == null) {
android { android {
compileSdkVersion 34 namespace = "com.amap.flutter.amap_map_example"
compileSdkVersion 35
lint { lint {
disable 'InvalidPackage' disable 'InvalidPackage'
@ -36,7 +37,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.amap.flutter.amap_map_example" applicationId "com.amap.flutter.amap_map_example"
minSdkVersion flutter.minSdkVersion minSdkVersion flutter.minSdkVersion
targetSdkVersion 33 targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
} }
@ -69,7 +70,7 @@ android {
jniLibs.srcDirs = ['libs'] jniLibs.srcDirs = ['libs']
} }
} }
ndkVersion '25.1.8937393' ndkVersion '27.0.12077973'
} }
dependencies { dependencies {
} }

View File

@ -19,6 +19,7 @@
<application <application
android:allowNativeHeapPointerTagging="false" android:allowNativeHeapPointerTagging="false"
android:enableOnBackInvokedCallback="true"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="amap_map_example"> android:label="amap_map_example">

View File

@ -1,4 +1,15 @@
org.gradle.jvmargs=-Xmx1536M ## For more details on how to configure your build environment visit
android.useAndroidX=true # http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
#Tue Mar 11 22:34:19 CST 2025
android.enableJetifier=true android.enableJetifier=true
#android.enableR8=true android.useAndroidX=true

View File

@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017 #Tue Mar 11 20:48:47 CST 2025
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip

View File

@ -18,8 +18,8 @@ pluginManagement {
plugins { plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.4.2" apply false id "com.android.application" version "8.9.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false id "org.jetbrains.kotlin.android" version "2.1.10" apply false
} }
include ":app" include ":app"

View File

@ -1,5 +1,5 @@
PODS: PODS:
- AMap3DMap (10.0.900): - AMap3DMap (10.1.200):
- AMapFoundation (>= 1.8.0) - AMapFoundation (>= 1.8.0)
- amap_map (1.0.8): - amap_map (1.0.8):
- AMap3DMap - AMap3DMap

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
class AnimatedCategoryItem extends StatelessWidget { class AnimatedCategoryItem extends StatelessWidget {
AnimatedCategoryItem({ AnimatedCategoryItem({
super.key,
required double startDelayFraction, required double startDelayFraction,
required this.controller, required this.controller,
required this.child, required this.child,
@ -27,7 +28,7 @@ class AnimatedCategoryItem extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AnimatedBuilder( return AnimatedBuilder(
animation: controller, animation: controller,
builder: (context, child) { builder: (BuildContext context, Widget? child) {
return Padding( return Padding(
padding: EdgeInsets.only(top: topPaddingAnimation.value), padding: EdgeInsets.only(top: topPaddingAnimation.value),
child: child, child: child,

View File

@ -4,7 +4,7 @@ import 'package:amap_map_example/widgets/amap_gridview.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class MoveCameraDemoPage extends StatefulWidget { class MoveCameraDemoPage extends StatefulWidget {
MoveCameraDemoPage({super.key}); const MoveCameraDemoPage({super.key});
@override @override
State<MoveCameraDemoPage> createState() => _BodyState(); State<MoveCameraDemoPage> createState() => _BodyState();
@ -29,7 +29,7 @@ class _BodyState extends State<MoveCameraDemoPage> {
Widget cameraOptions() { Widget cameraOptions() {
return Container( return Container(
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -45,7 +45,7 @@ class _BodyState extends State<MoveCameraDemoPage> {
} }
return ConstrainedBox( return ConstrainedBox(
constraints: BoxConstraints.expand(), constraints: const BoxConstraints.expand(),
child: Column( child: Column(
children: [ children: [
ConstrainedBox( ConstrainedBox(
@ -54,7 +54,7 @@ class _BodyState extends State<MoveCameraDemoPage> {
minHeight: MediaQuery.of(context).size.height * 0.7), minHeight: MediaQuery.of(context).size.height * 0.7),
child: Stack( child: Stack(
children: [ children: [
Container( SizedBox(
height: MediaQuery.of(context).size.height * 0.7, height: MediaQuery.of(context).size.height * 0.7,
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
child: amap, child: amap,
@ -66,28 +66,28 @@ class _BodyState extends State<MoveCameraDemoPage> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
InkResponse( InkResponse(
onTap: _zoomIn,
child: Container( child: Container(
child: Icon( width: 40,
height: 40,
color: Colors.blue,
child: const Icon(
Icons.add, Icons.add,
color: Colors.white, color: Colors.white,
), ),
width: 40,
height: 40,
color: Colors.blue,
), ),
onTap: _zoomIn,
), ),
InkResponse( InkResponse(
onTap: _zoomOut,
child: Container( child: Container(
child: Icon( color: Colors.blue,
width: 40,
height: 40,
child: const Icon(
Icons.remove, Icons.remove,
color: Colors.white, color: Colors.white,
), ),
color: Colors.blue,
width: 40,
height: 40,
), ),
onTap: _zoomOut,
), ),
], ],
), ),
@ -103,14 +103,14 @@ class _BodyState extends State<MoveCameraDemoPage> {
? Container( ? Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
color: Colors.grey, color: Colors.grey,
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
_currentZoom!, _currentZoom!,
style: TextStyle(color: Colors.white), style: const TextStyle(color: Colors.white),
), ),
) )
: SizedBox(), : const SizedBox(),
Container( Container(
child: cameraOptions(), child: cameraOptions(),
), ),
@ -141,7 +141,7 @@ class _BodyState extends State<MoveCameraDemoPage> {
void _changeCameraPosition() { void _changeCameraPosition() {
_mapController?.moveCamera( _mapController?.moveCamera(
CameraUpdate.newCameraPosition( CameraUpdate.newCameraPosition(
CameraPosition( const CameraPosition(
//中心点 //中心点
target: LatLng(31.230378, 121.473658), target: LatLng(31.230378, 121.473658),
//缩放级别 //缩放级别
@ -184,8 +184,8 @@ class _BodyState extends State<MoveCameraDemoPage> {
_mapController?.moveCamera( _mapController?.moveCamera(
CameraUpdate.newLatLngBounds( CameraUpdate.newLatLngBounds(
LatLngBounds( LatLngBounds(
southwest: LatLng(33.789925, 104.838326), southwest: const LatLng(33.789925, 104.838326),
northeast: LatLng(38.740688, 114.647472)), northeast: const LatLng(38.740688, 114.647472)),
15.0), 15.0),
animated: true, animated: true,
); );

View File

@ -6,13 +6,15 @@ import 'package:flutter/services.dart';
import 'package:x_amap_base/x_amap_base.dart'; import 'package:x_amap_base/x_amap_base.dart';
class AllMapConfigDemoPage extends StatefulWidget { class AllMapConfigDemoPage extends StatefulWidget {
const AllMapConfigDemoPage({super.key});
@override @override
State<StatefulWidget> createState() => _MapUiBodyState(); State<StatefulWidget> createState() => _MapUiBodyState();
} }
class _MapUiBodyState extends State<AllMapConfigDemoPage> { class _MapUiBodyState extends State<AllMapConfigDemoPage> {
//默认显示在北京天安门 //默认显示在北京天安门
static final CameraPosition _kInitialPosition = const CameraPosition( static const CameraPosition _kInitialPosition = CameraPosition(
target: LatLng(39.909187, 116.397451), target: LatLng(39.909187, 116.397451),
zoom: 10.0, zoom: 10.0,
); );
@ -127,7 +129,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
//ui控制 //ui控制
final List<Widget> uiOptions = [ final List<Widget> uiOptions = [
AMapSwitchButton( AMapSwitchButton(
label: Text('显示路况'), label: const Text('显示路况'),
defaultValue: _trafficEnabled, defaultValue: _trafficEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -136,7 +138,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示3D建筑物'), label: const Text('显示3D建筑物'),
defaultValue: _buildingsEnabled, defaultValue: _buildingsEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -145,7 +147,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示指南针'), label: const Text('显示指南针'),
defaultValue: _compassEnabled, defaultValue: _compassEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -154,7 +156,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示地图文字'), label: const Text('显示地图文字'),
defaultValue: _labelsEnabled, defaultValue: _labelsEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -163,7 +165,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示比例尺'), label: const Text('显示比例尺'),
defaultValue: _scaleEnabled, defaultValue: _scaleEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -172,7 +174,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('点击Poi'), label: const Text('点击Poi'),
defaultValue: _touchPoiEnabled, defaultValue: _touchPoiEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -181,7 +183,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('自定义地图'), label: const Text('自定义地图'),
defaultValue: _customStyleOptions.enabled, defaultValue: _customStyleOptions.enabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -194,7 +196,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
//手势开关 //手势开关
final List<Widget> gesturesOptions = [ final List<Widget> gesturesOptions = [
AMapSwitchButton( AMapSwitchButton(
label: Text('旋转'), label: const Text('旋转'),
defaultValue: _rotateGesturesEnabled, defaultValue: _rotateGesturesEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -203,7 +205,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('滑动'), label: const Text('滑动'),
defaultValue: _scrollGesturesEnabled, defaultValue: _scrollGesturesEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -212,7 +214,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('倾斜'), label: const Text('倾斜'),
defaultValue: _tiltGesturesEnabled, defaultValue: _tiltGesturesEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -221,7 +223,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
}, },
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('缩放'), label: const Text('缩放'),
defaultValue: _zoomGesturesEnabled, defaultValue: _zoomGesturesEnabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -233,14 +235,14 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
Widget mapTypeOptions() { Widget mapTypeOptions() {
return Container( return Container(
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text('地图样式', style: TextStyle(fontWeight: FontWeight.w600)), const Text('地图样式', style: TextStyle(fontWeight: FontWeight.w600)),
Container( Container(
padding: EdgeInsets.only(left: 10), padding: const EdgeInsets.only(left: 10),
child: createGridView(mapTypeList), child: createGridView(mapTypeList),
), ),
], ],
@ -250,15 +252,15 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
Widget myLocationStyleContainer() { Widget myLocationStyleContainer() {
return Container( return Container(
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
// Text('定位小蓝点', style: TextStyle(fontWeight: FontWeight.w600)), // Text('定位小蓝点', style: TextStyle(fontWeight: FontWeight.w600)),
AMapSwitchButton( AMapSwitchButton(
label: label: const Text('定位小蓝点',
Text('定位小蓝点', style: TextStyle(fontWeight: FontWeight.w600)), style: TextStyle(fontWeight: FontWeight.w600)),
defaultValue: _myLocationStyleOptions.enabled, defaultValue: _myLocationStyleOptions.enabled,
onSwitchChanged: (value) => { onSwitchChanged: (value) => {
setState(() { setState(() {
@ -273,14 +275,14 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
Widget uiOptionsWidget() { Widget uiOptionsWidget() {
return Container( return Container(
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text('UI操作', style: TextStyle(fontWeight: FontWeight.w600)), const Text('UI操作', style: TextStyle(fontWeight: FontWeight.w600)),
Container( Container(
padding: EdgeInsets.only(left: 10), padding: const EdgeInsets.only(left: 10),
child: createGridView(uiOptions), child: createGridView(uiOptions),
), ),
], ],
@ -290,14 +292,14 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
Widget gesturesOptiosWeidget() { Widget gesturesOptiosWeidget() {
return Container( return Container(
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text('手势控制', style: TextStyle(fontWeight: FontWeight.w600)), const Text('手势控制', style: TextStyle(fontWeight: FontWeight.w600)),
Container( Container(
padding: EdgeInsets.only(left: 10), padding: const EdgeInsets.only(left: 10),
child: createGridView(gesturesOptions), child: createGridView(gesturesOptions),
), ),
], ],
@ -364,7 +366,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
Widget createGridView(List<Widget> widgets) { Widget createGridView(List<Widget> widgets) {
return GridView.count( return GridView.count(
primary: false, primary: false,
physics: NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
//水平子Widget之间间距 //水平子Widget之间间距
crossAxisSpacing: 1.0, crossAxisSpacing: 1.0,
//垂直子Widget之间间距 //垂直子Widget之间间距
@ -379,7 +381,7 @@ class _MapUiBodyState extends State<AllMapConfigDemoPage> {
//移动地图中心点到首开广场 //移动地图中心点到首开广场
void _moveCameraToShoukai() { void _moveCameraToShoukai() {
_controller.moveCamera(CameraUpdate.newCameraPosition(CameraPosition( _controller.moveCamera(CameraUpdate.newCameraPosition(const CameraPosition(
target: LatLng(39.993306, 116.473004), target: LatLng(39.993306, 116.473004),
zoom: 18, zoom: 18,
tilt: 30, tilt: 30,

View File

@ -2,7 +2,7 @@ import 'package:amap_map/amap_map.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class MinMaxZoomDemoPage extends StatefulWidget { class MinMaxZoomDemoPage extends StatefulWidget {
MinMaxZoomDemoPage({super.key}); const MinMaxZoomDemoPage({super.key});
@override @override
State<MinMaxZoomDemoPage> createState() => _BodyState(); State<MinMaxZoomDemoPage> createState() => _BodyState();
@ -22,7 +22,7 @@ class _BodyState extends State<MinMaxZoomDemoPage> {
minMaxZoomPreference: MinMaxZoomPreference(_minZoom, _maxZoom), minMaxZoomPreference: MinMaxZoomPreference(_minZoom, _maxZoom),
); );
return ConstrainedBox( return ConstrainedBox(
constraints: BoxConstraints.expand(), constraints: const BoxConstraints.expand(),
child: Stack( child: Stack(
children: [ children: [
Container( Container(
@ -40,24 +40,24 @@ class _BodyState extends State<MinMaxZoomDemoPage> {
Container( Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
color: Colors.grey, color: Colors.grey,
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
'当前限制的最小最大缩放级别是:[$_minZoom, $_maxZoom]', '当前限制的最小最大缩放级别是:[$_minZoom, $_maxZoom]',
style: TextStyle(color: Colors.blue), style: const TextStyle(color: Colors.blue),
), ),
), ),
_currentZoom != null _currentZoom != null
? Container( ? Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
color: Colors.grey, color: Colors.grey,
padding: EdgeInsets.all(5), padding: const EdgeInsets.all(5),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
_currentZoom!, _currentZoom!,
style: TextStyle(color: Colors.white), style: const TextStyle(color: Colors.white),
)) ))
: SizedBox(), : const SizedBox(),
], ],
), ),
), ),
@ -69,7 +69,7 @@ class _BodyState extends State<MinMaxZoomDemoPage> {
children: [ children: [
InkResponse( InkResponse(
child: Container( child: Container(
child: Icon( child: const Icon(
Icons.add, Icons.add,
color: Colors.white, color: Colors.white,
), ),
@ -81,7 +81,7 @@ class _BodyState extends State<MinMaxZoomDemoPage> {
), ),
InkResponse( InkResponse(
child: Container( child: Container(
child: Icon( child: const Icon(
Icons.remove, Icons.remove,
color: Colors.white, color: Colors.white,
), ),

View File

@ -3,7 +3,7 @@ import 'package:x_amap_base/x_amap_base.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class MultiMapDemoPage extends StatefulWidget { class MultiMapDemoPage extends StatefulWidget {
const MultiMapDemoPage(); const MultiMapDemoPage({super.key});
@override @override
State<StatefulWidget> createState() => _MultiMapDemoState(); State<StatefulWidget> createState() => _MultiMapDemoState();
} }
@ -14,7 +14,7 @@ class _MultiMapDemoState extends State<MultiMapDemoPage> {
return Container( return Container(
height: MediaQuery.of(context).size.height, height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
child: Column( child: const Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[

View File

@ -39,8 +39,8 @@ class _State extends State<CustomInfoWindowDemoPage> {
position: markPostion, position: markPostion,
icon: _markerIcon!, icon: _markerIcon!,
infoWindow: InfoWindow(title: '$markerCount 个Marker'), infoWindow: InfoWindow(title: '$markerCount 个Marker'),
onTap: (markerId) => _onMarkerTapped(markerId), onTap: (String markerId) => _onMarkerTapped(markerId),
onDragEnd: (markerId, endPosition) => onDragEnd: (String markerId, LatLng endPosition) =>
_onMarkerDragEnd(markerId, endPosition), _onMarkerDragEnd(markerId, endPosition),
); );
@ -196,7 +196,7 @@ class _State extends State<CustomInfoWindowDemoPage> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: <Widget>[
Container( Container(
height: MediaQuery.of(context).size.height * 0.6, height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
@ -212,64 +212,64 @@ class _State extends State<CustomInfoWindowDemoPage> {
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('添加'),
onPressed: _add, onPressed: _add,
child: const Text('添加'),
), ),
TextButton( TextButton(
child: const Text('移除'),
onPressed: onPressed:
(selectedMarkerId == null) ? null : _remove, (selectedMarkerId == null) ? null : _remove,
child: const Text('移除'),
), ),
TextButton( TextButton(
child: const Text('更新InfoWidow'),
onPressed: onPressed:
(selectedMarkerId == null) ? null : _changeInfo, (selectedMarkerId == null) ? null : _changeInfo,
child: const Text('更新InfoWidow'),
), ),
TextButton( TextButton(
child: const Text('修改锚点'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changeAnchor, : _changeAnchor,
child: const Text('修改锚点'),
), ),
TextButton( TextButton(
child: const Text('修改透明度'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changeAlpha, : _changeAlpha,
child: const Text('修改透明度'),
), ),
], ],
), ),
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('全部移除'),
onPressed: _markers.isNotEmpty ? _removeAll : null, onPressed: _markers.isNotEmpty ? _removeAll : null,
child: const Text('全部移除'),
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('允许拖动'), label: const Text('允许拖动'),
onSwitchChanged: (selectedMarkerId == null) onSwitchChanged: (selectedMarkerId == null)
? null ? null
: _toggleDraggable, : _toggleDraggable,
defaultValue: false, defaultValue: false,
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示'), label: const Text('显示'),
onSwitchChanged: (selectedMarkerId == null) onSwitchChanged: (selectedMarkerId == null)
? null ? null
: _toggleVisible, : _toggleVisible,
defaultValue: true, defaultValue: true,
), ),
TextButton( TextButton(
child: const Text('修改坐标'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changePosition, : _changePosition,
child: const Text('修改坐标'),
), ),
TextButton( TextButton(
child: const Text('修改旋转角度'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changeRotation, : _changeRotation,
child: const Text('修改旋转角度'),
), ),
], ],
), ),
@ -300,8 +300,8 @@ class CustomInfoWindowAdapter extends BaseInfoWindowAdapter {
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.circular(8.0), borderRadius: BorderRadius.circular(8.0),
boxShadow: [ boxShadow: <BoxShadow>[
BoxShadow( const BoxShadow(
color: Colors.black26, color: Colors.black26,
blurRadius: 4.0, blurRadius: 4.0,
spreadRadius: 2.0, spreadRadius: 2.0,
@ -310,10 +310,10 @@ class CustomInfoWindowAdapter extends BaseInfoWindowAdapter {
), ),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: <Widget>[
Text( Text(
marker.infoWindow.title ?? 'No Title', marker.infoWindow.title ?? 'No Title',
style: TextStyle(fontWeight: FontWeight.bold), style: const TextStyle(fontWeight: FontWeight.bold),
), ),
Text( Text(
marker.infoWindow.snippet ?? 'No Snippet', marker.infoWindow.snippet ?? 'No Snippet',

View File

@ -265,64 +265,64 @@ class _State extends State<MarkerConfigDemoPage> {
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('添加'),
onPressed: _add, onPressed: _add,
child: const Text('添加'),
), ),
TextButton( TextButton(
child: const Text('移除'),
onPressed: onPressed:
(selectedMarkerId == null) ? null : _remove, (selectedMarkerId == null) ? null : _remove,
child: const Text('移除'),
), ),
TextButton( TextButton(
child: const Text('更新InfoWidow'),
onPressed: onPressed:
(selectedMarkerId == null) ? null : _changeInfo, (selectedMarkerId == null) ? null : _changeInfo,
child: const Text('更新InfoWidow'),
), ),
TextButton( TextButton(
child: const Text('修改锚点'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changeAnchor, : _changeAnchor,
child: const Text('修改锚点'),
), ),
TextButton( TextButton(
child: const Text('修改透明度'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changeAlpha, : _changeAlpha,
child: const Text('修改透明度'),
), ),
], ],
), ),
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('全部移除'),
onPressed: _markers.isNotEmpty ? _removeAll : null, onPressed: _markers.isNotEmpty ? _removeAll : null,
child: const Text('全部移除'),
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('允许拖动'), label: const Text('允许拖动'),
onSwitchChanged: (selectedMarkerId == null) onSwitchChanged: (selectedMarkerId == null)
? null ? null
: _toggleDraggable, : _toggleDraggable,
defaultValue: false, defaultValue: false,
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示'), label: const Text('显示'),
onSwitchChanged: (selectedMarkerId == null) onSwitchChanged: (selectedMarkerId == null)
? null ? null
: _toggleVisible, : _toggleVisible,
defaultValue: true, defaultValue: true,
), ),
TextButton( TextButton(
child: const Text('修改坐标'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changePosition, : _changePosition,
child: const Text('修改坐标'),
), ),
TextButton( TextButton(
child: const Text('修改旋转角度'),
onPressed: (selectedMarkerId == null) onPressed: (selectedMarkerId == null)
? null ? null
: _changeRotation, : _changeRotation,
child: const Text('修改旋转角度'),
), ),
], ],
), ),

View File

@ -3,17 +3,19 @@ import 'package:x_amap_base/x_amap_base.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class MarkerCustomIconPage extends StatefulWidget { class MarkerCustomIconPage extends StatefulWidget {
const MarkerCustomIconPage({super.key});
@override @override
State<MarkerCustomIconPage> createState() => _BodyState(); State<MarkerCustomIconPage> createState() => _BodyState();
} }
class _BodyState extends State<MarkerCustomIconPage> { class _BodyState extends State<MarkerCustomIconPage> {
static final LatLng markerPosition = const LatLng(39.909187, 116.397451); static const LatLng markerPosition = LatLng(39.909187, 116.397451);
final Map<String, Marker> _initMarkerMap = <String, Marker>{}; final Map<String, Marker> _initMarkerMap = <String, Marker>{};
String? _currentMarkerId; String? _currentMarkerId;
bool _hasInitMarker = false; bool _hasInitMarker = false;
static final String _startIconPath = 'assets/start.png'; static const String _startIconPath = 'assets/start.png';
static final String _endIconPath = 'assets/end.png'; static const String _endIconPath = 'assets/end.png';
String _iconPath = _startIconPath; String _iconPath = _startIconPath;
void _initMarker(BuildContext context) async { void _initMarker(BuildContext context) async {
if (_hasInitMarker) { if (_hasInitMarker) {

View File

@ -110,7 +110,7 @@ class _State extends State<PolygonDemoPage> {
List<LatLng> currentPoints = polygon.points; List<LatLng> currentPoints = polygon.points;
List<LatLng> newPoints = <LatLng>[]; List<LatLng> newPoints = <LatLng>[];
newPoints.addAll(currentPoints); newPoints.addAll(currentPoints);
newPoints.add(LatLng(39.828809, 116.360364)); newPoints.add(const LatLng(39.828809, 116.360364));
setState(() { setState(() {
_polygons[selectedPolygonId!] = polygon.copyWith( _polygons[selectedPolygonId!] = polygon.copyWith(
@ -133,7 +133,7 @@ class _State extends State<PolygonDemoPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final AMapWidget map = AMapWidget( final AMapWidget map = AMapWidget(
initialCameraPosition: initialCameraPosition:
CameraPosition(target: LatLng(39.828809, 116.360364), zoom: 13), const CameraPosition(target: LatLng(39.828809, 116.360364), zoom: 13),
onMapCreated: _onMapCreated, onMapCreated: _onMapCreated,
polygons: Set<Polygon>.of(_polygons.values), polygons: Set<Polygon>.of(_polygons.values),
); );
@ -159,42 +159,42 @@ class _State extends State<PolygonDemoPage> {
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('添加'),
onPressed: _add, onPressed: _add,
child: const Text('添加'),
), ),
TextButton( TextButton(
child: const Text('删除'),
onPressed: onPressed:
(selectedPolygonId == null) ? null : _remove, (selectedPolygonId == null) ? null : _remove,
child: const Text('删除'),
), ),
TextButton( TextButton(
child: const Text('修改边框宽度'),
onPressed: (selectedPolygonId == null) onPressed: (selectedPolygonId == null)
? null ? null
: _changeStrokeWidth, : _changeStrokeWidth,
child: const Text('修改边框宽度'),
), ),
], ],
), ),
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('修改边框和填充色'),
onPressed: (selectedPolygonId == null) onPressed: (selectedPolygonId == null)
? null ? null
: _changeColors, : _changeColors,
child: const Text('修改边框和填充色'),
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示'), label: const Text('显示'),
onSwitchChanged: (selectedPolygonId == null) onSwitchChanged: (selectedPolygonId == null)
? null ? null
: _toggleVisible, : _toggleVisible,
defaultValue: true, defaultValue: true,
), ),
TextButton( TextButton(
child: const Text('修改坐标'),
onPressed: (selectedPolygonId == null) onPressed: (selectedPolygonId == null)
? null ? null
: _changePoints, : _changePoints,
child: const Text('修改坐标'),
), ),
], ],
), ),

View File

@ -171,7 +171,7 @@ class _State extends State<PolylineDemoPage> {
List<LatLng> currentPoints = polyline.points; List<LatLng> currentPoints = polyline.points;
List<LatLng> newPoints = <LatLng>[]; List<LatLng> newPoints = <LatLng>[];
newPoints.addAll(currentPoints); newPoints.addAll(currentPoints);
newPoints.add(LatLng(39.835347, 116.34575)); newPoints.add(const LatLng(39.835347, 116.34575));
setState(() { setState(() {
_polylines[selectedPolylineId!] = polyline.copyWith( _polylines[selectedPolylineId!] = polyline.copyWith(
@ -218,28 +218,28 @@ class _State extends State<PolylineDemoPage> {
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('添加'),
onPressed: _add, onPressed: _add,
child: const Text('添加'),
), ),
TextButton( TextButton(
child: const Text('删除'),
onPressed: onPressed:
(selectedPolylineId == null) ? null : _remove, (selectedPolylineId == null) ? null : _remove,
child: const Text('删除'),
), ),
TextButton( TextButton(
child: const Text('修改线宽'),
onPressed: (selectedPolylineId == null) onPressed: (selectedPolylineId == null)
? null ? null
: _changeWidth, : _changeWidth,
child: const Text('修改线宽'),
), ),
TextButton( TextButton(
child: const Text('修改透明度'),
onPressed: (selectedPolylineId == null) onPressed: (selectedPolylineId == null)
? null ? null
: _changeAlpha, : _changeAlpha,
child: const Text('修改透明度'),
), ),
AMapSwitchButton( AMapSwitchButton(
label: Text('显示'), label: const Text('显示'),
onSwitchChanged: (selectedPolylineId == null) onSwitchChanged: (selectedPolylineId == null)
? null ? null
: _toggleVisible, : _toggleVisible,
@ -250,34 +250,34 @@ class _State extends State<PolylineDemoPage> {
Column( Column(
children: <Widget>[ children: <Widget>[
TextButton( TextButton(
child: const Text('修改颜色'),
onPressed: (selectedPolylineId == null) onPressed: (selectedPolylineId == null)
? null ? null
: _changeColor, : _changeColor,
child: const Text('修改颜色'),
), ),
TextButton( TextButton(
child: const Text('修改线头样式'),
onPressed: (selectedPolylineId == null) onPressed: (selectedPolylineId == null)
? null ? null
: _changeCapType, : _changeCapType,
child: const Text('修改线头样式'),
), ),
TextButton( TextButton(
child: const Text('修改连接样式'),
onPressed: (selectedPolylineId == null) onPressed: (selectedPolylineId == null)
? null ? null
: _changeJointType, : _changeJointType,
child: const Text('修改连接样式'),
), ),
TextButton( TextButton(
child: const Text('修改虚线类型'),
onPressed: (selectedPolylineId == null) onPressed: (selectedPolylineId == null)
? null ? null
: _changeDashLineType, : _changeDashLineType,
child: const Text('修改虚线类型'),
), ),
TextButton( TextButton(
child: const Text('修改坐标'),
onPressed: (selectedPolylineId == null) onPressed: (selectedPolylineId == null)
? null ? null
: _changePoints, : _changePoints,
child: const Text('修改坐标'),
), ),
], ],
), ),

View File

@ -13,7 +13,6 @@ dependencies:
sdk: flutter sdk: flutter
permission_handler: ^11.3.1 permission_handler: ^11.3.1
flutter_plugin_android_lifecycle: ^2.0.21
amap_map: amap_map:
path: ../ path: ../

View File

@ -3,36 +3,36 @@ import 'package:x_amap_base/x_amap_base.dart';
void main() { void main() {
test('Distance between two different point', () { test('Distance between two different point', () {
LatLng p1 = LatLng(1, 1); LatLng p1 = const LatLng(1, 1);
LatLng p2 = LatLng(2, 2); LatLng p2 = const LatLng(2, 2);
double distance = AMapTools.distanceBetween(p1, p2); double distance = AMapTools.distanceBetween(p1, p2);
expect(distance, 157401.56104583555); expect(distance, 157401.56104583555);
}); });
test('Distance between two same point', () { test('Distance between two same point', () {
LatLng p1 = LatLng(1, 1); LatLng p1 = const LatLng(1, 1);
LatLng p2 = LatLng(1, 1); LatLng p2 = const LatLng(1, 1);
double distance = AMapTools.distanceBetween(p1, p2); double distance = AMapTools.distanceBetween(p1, p2);
expect(distance, 0); expect(distance, 0);
}); });
test('Distance between two different point with equal lat', () { test('Distance between two different point with equal lat', () {
LatLng p1 = LatLng(1, 1); LatLng p1 = const LatLng(1, 1);
LatLng p2 = LatLng(1, 2); LatLng p2 = const LatLng(1, 2);
double distance = AMapTools.distanceBetween(p1, p2); double distance = AMapTools.distanceBetween(p1, p2);
expect(distance, 111302.53586533663); expect(distance, 111302.53586533663);
}); });
test('Distance between two different point with equal lng', () { test('Distance between two different point with equal lng', () {
LatLng p1 = LatLng(1, 1); LatLng p1 = const LatLng(1, 1);
LatLng p2 = LatLng(2, 1); LatLng p2 = const LatLng(2, 1);
double distance = AMapTools.distanceBetween(p1, p2); double distance = AMapTools.distanceBetween(p1, p2);
expect(distance, 111319.49079327357); expect(distance, 111319.49079327357);
}); });
test('Distance between two different point with close point', () { test('Distance between two different point with close point', () {
LatLng p1 = LatLng(39.938212, 116.455139); LatLng p1 = const LatLng(39.938212, 116.455139);
LatLng p2 = LatLng(39.987656, 116.265605); LatLng p2 = const LatLng(39.987656, 116.265605);
double distance = AMapTools.distanceBetween(p1, p2); double distance = AMapTools.distanceBetween(p1, p2);
expect(distance, 17082.425889709597); expect(distance, 17082.425889709597);
}); });

View File

@ -11,7 +11,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
/// 高德地图Flutter插件入口文件 /// 高德地图Flutter插件入口文件
library amap_map; library;
import 'dart:async'; import 'dart:async';

View File

@ -96,12 +96,12 @@ class Marker extends BaseOverlay {
(alpha != null ? (alpha < 0 ? 0 : (alpha > 1 ? 1 : alpha)) : alpha), (alpha != null ? (alpha < 0 ? 0 : (alpha > 1 ? 1 : alpha)) : alpha),
// ignore: unnecessary_null_comparison // ignore: unnecessary_null_comparison
anchor = (anchor == null anchor = (anchor == null
? Offset(0.5, 1.0) ? const Offset(0.5, 1.0)
: ((anchor.dx < 0 || : ((anchor.dx < 0 ||
anchor.dx > 1 || anchor.dx > 1 ||
anchor.dy < 0 || anchor.dy < 0 ||
anchor.dy > 1) anchor.dy > 1)
? Offset(0.5, 1.0) ? const Offset(0.5, 1.0)
: anchor)), : anchor)),
super(); super();

View File

@ -77,8 +77,8 @@ class Polygon extends BaseOverlay {
addIfPresent('id', id); addIfPresent('id', id);
json['points'] = _pointsToJson(); json['points'] = _pointsToJson();
addIfPresent('strokeWidth', strokeWidth); addIfPresent('strokeWidth', strokeWidth);
addIfPresent('strokeColor', strokeColor.value); addIfPresent('strokeColor', strokeColor.toARGB32());
addIfPresent('fillColor', fillColor.value); addIfPresent('fillColor', fillColor.toARGB32());
addIfPresent('visible', visible); addIfPresent('visible', visible);
addIfPresent('joinType', joinType.index); addIfPresent('joinType', joinType.index);
return json; return json;

View File

@ -155,7 +155,7 @@ class Polyline extends BaseOverlay {
addIfPresent('capType', capType.index); addIfPresent('capType', capType.index);
addIfPresent('joinType', joinType.index); addIfPresent('joinType', joinType.index);
addIfPresent('customTexture', customTexture?.toMap()); addIfPresent('customTexture', customTexture?.toMap());
addIfPresent('color', color.value); addIfPresent('color', color.toARGB32());
return json; return json;
} }

View File

@ -167,8 +167,8 @@ class MyLocationStyleOptions {
} }
addIfPresent('enabled', enabled); addIfPresent('enabled', enabled);
addIfPresent('circleFillColor', circleFillColor?.value); addIfPresent('circleFillColor', circleFillColor?.toARGB32());
addIfPresent('circleStrokeColor', circleStrokeColor?.value); addIfPresent('circleStrokeColor', circleStrokeColor?.toARGB32());
addIfPresent('circleStrokeWidth', circleStrokeWidth); addIfPresent('circleStrokeWidth', circleStrokeWidth);
addIfPresent('icon', icon?.toMap()); addIfPresent('icon', icon?.toMap());
return json; return json;

View File

@ -1,6 +1,6 @@
name: amap_map name: amap_map
description: Amap SDK Flutter plugin for integrating AMapSDK in iOS and Android applications. 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 homepage: https://github.com/kuloud/amap_map
issue_tracker: https://github.com/kuloud/amap_map/issues issue_tracker: https://github.com/kuloud/amap_map/issues
platforms: platforms:
@ -26,9 +26,9 @@ dependencies:
x_common: ^1.0.4 x_common: ^1.0.4
dev_dependencies: dev_dependencies:
flutter_lints: ^5.0.0
flutter_test: flutter_test:
sdk: flutter sdk: flutter
lints: ^4.0.0
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec