From 5ecf421da4f087d2a04e35b15911bd67f2050886 Mon Sep 17 00:00:00 2001 From: Kuloud Date: Fri, 29 Dec 2023 21:48:01 +0800 Subject: [PATCH] release: 1.0.0+8 --- CHANGELOG.md | 4 +++ README.md | 29 ++++++++++++++++++++- example/lib/main.dart | 5 ++++ example/lib/pages/map/custom_map_style.dart | 6 ++--- example/lib/pages/map/map_all_config.dart | 5 ++-- lib/amap_map.dart | 1 + lib/src/amap_initializer.dart | 25 ++++++++++++++++++ lib/src/amap_widget.dart | 13 ++++----- pubspec.yaml | 2 +- 9 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 lib/src/amap_initializer.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd327a..9e5d499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0+8 +2023-12-29. +* 废弃 `AMapWidget` 中的 `apiKey` / `privacyStatement` 字段,使用 `AMapInitializer` 初始化 + ## 1.0.0+7 - 2023-12-26. * github action automate publish support diff --git a/README.md b/README.md index 01f5773..c0f759f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,34 @@ flutter pub add amap_map ## Demo -``` Dart +### 初始化 +在runApp启动的**第一个**Widget中,使用`context`进行组件初始化 + +```dart +import 'package:amap_map/amap_map.dart'; +import 'package:x_amap_base/x_amap_base.dart'; // AMapApiKey 和 AMapPrivacyStatement 定义在 package `x_amap_base` 中,需要一并引入 + +class DemoWidget extends State { + + @override + Widget build(BuildContext context) { + AMapInitializer.init(context, ConstConfig.amapApiKeys); + + return Scaffold( + // ... + ); + } +} +``` +### 合规处理 +高德SDK合规使用方案请参考:https://lbs.amap.com/news/sdkhgsy ,需要进行授权交互,然后通知组件。 + +```dart +AMapInitializer.updatePrivacyAgree(ConstConfig.amapPrivacyStatement); +``` + +### 使用地图 +``` dart import 'package:amap_map_example/base_page.dart'; import 'package:flutter/material.dart'; diff --git a/example/lib/main.dart b/example/lib/main.dart index 9812f93..ddde422 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,3 +1,5 @@ +import 'package:amap_map/amap_map.dart'; +import 'package:amap_map_example/const_config.dart'; import 'package:amap_map_example/pages/overlays/marker_add_after_map.dart'; import 'package:amap_map_example/pages/overlays/marker_add_with_map.dart'; import 'package:amap_map_example/pages/overlays/marker_config.dart'; @@ -75,6 +77,7 @@ class DemoWidget extends State { @override void initState() { super.initState(); + _checkPermissions(); } @@ -94,6 +97,8 @@ class DemoWidget extends State { @override Widget build(BuildContext context) { + AMapInitializer.init(context, ConstConfig.amapApiKeys); + AMapInitializer.updatePrivacyAgree(ConstConfig.amapPrivacyStatement); return Scaffold( appBar: AppBar(title: const Text('高德地图示例')), body: Container( diff --git a/example/lib/pages/map/custom_map_style.dart b/example/lib/pages/map/custom_map_style.dart index 5590f08..a118d5d 100644 --- a/example/lib/pages/map/custom_map_style.dart +++ b/example/lib/pages/map/custom_map_style.dart @@ -34,9 +34,9 @@ class _CustomMapStyleState extends State<_CustomMapStyleBody> { _customStyleOptions.styleExtraData = styleExtraByteData.buffer.asUint8List(); //如果需要加载完成后直接展示自定义地图,可以通过setState修改CustomStyleOptions的enable为true - // setState(() { - // _customStyleOptions.enabled = true; - // }); + setState(() { + _customStyleOptions.enabled = true; + }); } @override diff --git a/example/lib/pages/map/map_all_config.dart b/example/lib/pages/map/map_all_config.dart index ae9c440..eaf7150 100644 --- a/example/lib/pages/map/map_all_config.dart +++ b/example/lib/pages/map/map_all_config.dart @@ -88,8 +88,8 @@ class _MapUiBodyState extends State<_MapUiBody> { Widget build(BuildContext context) { final AMapWidget map = AMapWidget( ///必须正确设置的合规隐私声明,否则SDK不会工作,会造成地图白屏等问题。 - privacyStatement: ConstConfig.amapPrivacyStatement, - apiKey: ConstConfig.amapApiKeys, + // privacyStatement: ConstConfig.amapPrivacyStatement, + // apiKey: ConstConfig.amapApiKeys, initialCameraPosition: _kInitialPosition, mapType: _mapType, trafficEnabled: _trafficEnabled, @@ -362,6 +362,7 @@ class _MapUiBodyState extends State<_MapUiBody> { void onMapCreated(AMapController controller) { setState(() { _controller = controller; + printApprovalNumber(); }); } diff --git a/lib/amap_map.dart b/lib/amap_map.dart index 1faf6aa..079e17c 100644 --- a/lib/amap_map.dart +++ b/lib/amap_map.dart @@ -15,5 +15,6 @@ import 'package:flutter/services.dart'; export 'package:amap_map/src/types/types.dart'; +part 'src/amap_initializer.dart'; part 'src/amap_controller.dart'; part 'src/amap_widget.dart'; diff --git a/lib/src/amap_initializer.dart b/lib/src/amap_initializer.dart new file mode 100644 index 0000000..819b8c4 --- /dev/null +++ b/lib/src/amap_initializer.dart @@ -0,0 +1,25 @@ +part of amap_map; + +class AMapInitializer { + static AMapApiKey? _apiKey; + static AMapPrivacyStatement? _privacyStatement; + + AMapInitializer._(); + + static Future init(BuildContext context, AMapApiKey apiKey) async { + AMapUtil.init(context); + _apiKey = apiKey; + } + + /// 在app首次启动时必须传入高德合规声明配置[privacyStatement],后续如果没有变化不需要重复设置 + ///
  • [privacyStatement.hasContains] 隐私权政策是否包含高德开平隐私权政策
  • + ///
  • [privacyStatement.hasShow] 是否已经弹窗展示给用户
  • + ///
  • [privacyStatement.hasAgree] 隐私权政策是否已经取得用户同意
  • + /// 以上三个值,任何一个为false都会造成地图插件不工作(白屏情况) + /// + /// 高德SDK合规使用方案请参考:https://lbs.amap.com/news/sdkhgsy + /// + static updatePrivacyAgree(AMapPrivacyStatement privacyStatement) { + _privacyStatement = privacyStatement; + } +} diff --git a/lib/src/amap_widget.dart b/lib/src/amap_widget.dart index 003d0b9..5cfeafc 100644 --- a/lib/src/amap_widget.dart +++ b/lib/src/amap_widget.dart @@ -5,7 +5,7 @@ typedef void MapCreatedCallback(AMapController controller); ///用于展示高德地图的Widget class AMapWidget extends StatefulWidget { ///高德开放平台的key - /// + @Deprecated('高德开放平台的key,请通过AMapInitializer初始化设置,将在1.0.1+移除') final AMapApiKey? apiKey; /// 初始化时的地图中心点 @@ -92,11 +92,11 @@ class AMapWidget extends StatefulWidget { ///高德合规声明配置 /// /// 高德SDK合规使用方案请参考:https://lbs.amap.com/news/sdkhgsy + @Deprecated('高德开放平台的key,请通过AMapInitializer初始化设置,将在1.0.1+移除') final AMapPrivacyStatement? privacyStatement; /// 创建一个展示高德地图的widget /// - /// 如果使用的高德地图SDK的版本是8.1.0及以上版本, /// 在app首次启动时必须传入高德合规声明配置[privacyStatement],后续如果没有变化不需要重复设置 ///
  • [privacyStatement.hasContains] 隐私权政策是否包含高德开平隐私权政策
  • ///
  • [privacyStatement.hasShow] 是否已经弹窗展示给用户
  • @@ -108,8 +108,9 @@ class AMapWidget extends StatefulWidget { /// [AssertionError] will be thrown if [initialCameraPosition] is null; const AMapWidget({ Key? key, + @Deprecated('高德开放平台的key,请通过AMapInitializer初始化设置,将在1.0.1+移除') this.privacyStatement, - this.apiKey, + @Deprecated('高德开放平台的key,请通过AMapInitializer初始化设置,将在1.0.1+移除') this.apiKey, this.initialCameraPosition = const CameraPosition(target: LatLng(39.909187, 116.397451), zoom: 10), this.mapType = MapType.normal, @@ -155,10 +156,10 @@ class _MapState extends State { @override Widget build(BuildContext context) { - AMapUtil.init(context); final Map creationParams = { - 'privacyStatement': widget.privacyStatement?.toMap(), - 'apiKey': widget.apiKey?.toMap(), + 'privacyStatement': + widget.privacyStatement?.toMap() ?? AMapInitializer._privacyStatement, + 'apiKey': widget.apiKey?.toMap() ?? AMapInitializer._apiKey, 'initialCameraPosition': widget.initialCameraPosition.toMap(), 'options': _mapOptions.toMap(), 'markersToAdd': serializeOverlaySet(widget.markers), diff --git a/pubspec.yaml b/pubspec.yaml index df0ea29..5d292c0 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.0+7 +version: 1.0.0+8 homepage: https://github.com/kuloud/amap_map issue_tracker: https://github.com/kuloud/amap_map/issues platforms: