提交 d93bf6fe authored 作者: 袁静春's avatar 袁静春

提交:优化导航插件;

上级 bf7410aa
...@@ -25,7 +25,7 @@ EXTERNAL SOURCES: ...@@ -25,7 +25,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
AMapFoundation: f48153f724114b58da9b01875ab88a1f6856e3db AMapFoundation: f48153f724114b58da9b01875ab88a1f6856e3db
AMapNavi: 04727c06ec51fc4d7c57d83e2542da81b32f2f59 AMapNavi: 04727c06ec51fc4d7c57d83e2542da81b32f2f59
clx_map_navigation: 4eb146ec054cc72567c5b372d20ba4d0ed6ee365 clx_map_navigation: b73614901161608d76ebfe6ec266773bdfe00b26
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
......
...@@ -372,7 +372,7 @@ ...@@ -372,7 +372,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driverFlutter; PRODUCT_BUNDLE_IDENTIFIER = com.clx.driver;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
}; };
...@@ -496,7 +496,7 @@ ...@@ -496,7 +496,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driverFlutter; PRODUCT_BUNDLE_IDENTIFIER = com.clx.driver;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
}; };
...@@ -515,7 +515,7 @@ ...@@ -515,7 +515,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driverFlutter; PRODUCT_BUNDLE_IDENTIFIER = com.clx.driver;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
}; };
......
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:clx_map_navigation_example/map_config.dart'; import 'package:clx_map_navigation_example/map_config.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:clx_map_navigation/amap_navigation_widget.dart'; import 'package:clx_map_navigation/amap_navigation_widget.dart';
import 'package:clx_map_navigation/core/clx_map_navigation.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
...@@ -30,10 +28,15 @@ class _MyAppState extends State<MyApp> { ...@@ -30,10 +28,15 @@ class _MyAppState extends State<MyApp> {
), ),
body: const AMapNavigationWidget( body: const AMapNavigationWidget(
apiKey: AMapConfig.aMapApiKeys, apiKey: AMapConfig.aMapApiKeys,
startPoint: { "latitude": 39.993135, "longitude": 116.474175 }, // startPoint: { "latitude": 39.993135, "longitude": 116.474175 },
endPoint: { "latitude": 39.908791, "longitude": 116.321257 }, // endPoint: { "latitude": 39.908791, "longitude": 116.321257 },
startPoint: { "latitude": 37.820494, "longitude": 112.586248 },
endPoint: { "latitude": 39.911328, "longitude": 116.152583 },
onMapClosed: AMapConfig.onMapClosed,
), ),
), ),
); );
} }
} }
...@@ -2,10 +2,16 @@ import 'package:amap_flutter_base/amap_flutter_base.dart'; ...@@ -2,10 +2,16 @@ import 'package:amap_flutter_base/amap_flutter_base.dart';
class AMapConfig { class AMapConfig {
static const androidKey = "8395ac94201590a0e5cfe4c836b1d2c9"; static const androidKey = "8395ac94201590a0e5cfe4c836b1d2c9";
static const iosKey = "3d2ef3dd5e6da65e19e34d34d9a403a1"; static const iosKey = "3d2ef3dd5e6da65e19e34d34d9a403a1"; //com.clx.driver
static const AMapApiKey aMapApiKeys = AMapApiKey( static const AMapApiKey aMapApiKeys = AMapApiKey(
iosKey: iosKey, iosKey: iosKey,
androidKey: androidKey, androidKey: androidKey,
); );
static onMapClosed() {
print("----- onMapClosed ---- 处理完了");
}
} }
\ No newline at end of file
...@@ -156,6 +156,13 @@ packages: ...@@ -156,6 +156,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
stream_transform:
dependency: transitive
description:
name: stream_transform
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
......
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
if (self = [super init]) { if (self = [super init]) {
NSAssert([args isKindOfClass:[NSDictionary class]], @"传参错误"); NSAssert([args isKindOfClass:[NSDictionary class]], @"传参错误");
//构建methedChannel //构建methedChannel
NSString *channelName = [NSString stringWithFormat:@"amap_flutter_map_navigation_%lld", viewId]; //NSString *channelName = [NSString stringWithFormat:@"amap_flutter_map_navigation_lld", viewId];
NSString *channelName = [NSString stringWithFormat:@"clx_map_navigation"];
_channel = [FlutterMethodChannel methodChannelWithName:channelName _channel = [FlutterMethodChannel methodChannelWithName:channelName
binaryMessenger:registrar.messenger]; binaryMessenger:registrar.messenger];
_viewId = viewId; _viewId = viewId;
...@@ -240,6 +241,13 @@ ...@@ -240,6 +241,13 @@
[driveView removeFromSuperview]; [driveView removeFromSuperview];
[[AMapNaviDriveManager sharedInstance] stopNavi]; [[AMapNaviDriveManager sharedInstance] stopNavi];
[[AMapNaviDriveManager sharedInstance] removeDataRepresentative:_driveView]; [[AMapNaviDriveManager sharedInstance] removeDataRepresentative:_driveView];
NSMutableDictionary *arguments = [NSMutableDictionary dictionary];
[arguments setValue:@"退出" forKey:@"msg"];
if (_channel) {
NSLog(@"driveViewCloseButtonClicked - 退出: %@", arguments);
[_channel invokeMethod:@"navigationClosed" arguments:arguments];
}
} }
- (void)driveViewMoreButtonClicked:(AMapNaviDriveView *)driveView { - (void)driveViewMoreButtonClicked:(AMapNaviDriveView *)driveView {
......
import 'dart:async';
import 'package:clx_map_navigation/core/amap_navigation_util.dart'; import 'package:clx_map_navigation/core/amap_navigation_util.dart';
import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart'; import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart';
import 'package:clx_map_navigation/core/clx_map_navigation_platform_interface.dart'; import 'package:clx_map_navigation/core/clx_map_navigation_platform_interface.dart';
import 'package:clx_map_navigation/core/map_event.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart'; import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:flutter/services.dart';
final MethodChannelClxMapNavigation _methodChannel = ClxMapNavigationPlatform.instance as MethodChannelClxMapNavigation; final MethodChannelClxMapNavigation _methodChannel = ClxMapNavigationPlatform.instance as MethodChannelClxMapNavigation;
typedef void MapClosedCallback();
class AMapNavigationWidget extends StatefulWidget { class AMapNavigationWidget extends StatefulWidget {
/// 高德开放平台的key /// 高德开放平台的key
final AMapApiKey? apiKey; final AMapApiKey? apiKey;
/// 起点 /// 起点
final Map? startPoint; final Map? startPoint;
/// 终点 /// 终点
final Map? endPoint; final Map? endPoint;
/// 需要应用到地图上的手势集合
///需要应用到地图上的手势集合
final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers; final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers;
/// 导航地图底部退出的回调
final MapClosedCallback? onMapClosed;
const AMapNavigationWidget({ const AMapNavigationWidget({
Key? key, Key? key,
...@@ -28,6 +31,7 @@ class AMapNavigationWidget extends StatefulWidget { ...@@ -28,6 +31,7 @@ class AMapNavigationWidget extends StatefulWidget {
required this.startPoint, required this.startPoint,
required this.endPoint, required this.endPoint,
this.gestureRecognizers = const <Factory<OneSequenceGestureRecognizer>>{}, this.gestureRecognizers = const <Factory<OneSequenceGestureRecognizer>>{},
this.onMapClosed,
}) : super(key: key); }) : super(key: key);
@override @override
...@@ -35,9 +39,33 @@ class AMapNavigationWidget extends StatefulWidget { ...@@ -35,9 +39,33 @@ class AMapNavigationWidget extends StatefulWidget {
} }
class _MapNavigationState extends State<AMapNavigationWidget> { class _MapNavigationState extends State<AMapNavigationWidget> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_setupChannelsConfig();
_connectStreams();
}
_setupChannelsConfig() {
_methodChannel.channel().setMethodCallHandler((call) => _handleMethodCall(call));
}
_connectStreams() {
print("---_connectStreams---");
if (widget.onMapClosed != null) {
_methodChannel.onMapClosed().listen((MapClosedEvent e) => widget.onMapClosed!());
}
}
/// 原生与Flutter交互
Future<dynamic> _handleMethodCall(MethodCall call) async {
print("------_handleMethodCall ----- ");
switch (call.method) {
case 'navigationClosed':
_methodChannel.getMapEventStreamController().add(MapClosedEvent(""));
break;
}
} }
@override @override
...@@ -52,6 +80,7 @@ class _MapNavigationState extends State<AMapNavigationWidget> { ...@@ -52,6 +80,7 @@ class _MapNavigationState extends State<AMapNavigationWidget> {
creationParams, creationParams,
widget.gestureRecognizers, widget.gestureRecognizers,
onPlatformViewCreated, onPlatformViewCreated,
widget.onMapClosed,
); );
return mapView; return mapView;
} }
......
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'clx_map_navigation_platform_interface.dart';
class ClxMapNavigation {
Future<String?> getPlatformVersion() {
return ClxMapNavigationPlatform.instance.getPlatformVersion();
}
Widget buildMapNavigationView(
Map<String, dynamic> creationParams,
Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers,
void Function(int id) onPlatformViewCreated) {
return ClxMapNavigationPlatform.instance.buildMapNavigationView(
creationParams,
gestureRecognizers,
onPlatformViewCreated,
);
}
}
import 'dart:async';
import 'package:clx_map_navigation/amap_navigation_widget.dart';
import 'package:clx_map_navigation/core/map_event.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'clx_map_navigation_platform_interface.dart'; import 'clx_map_navigation_platform_interface.dart';
import 'package:stream_transform/stream_transform.dart';
const VIEW_TYPE = 'clx_map_navigation'; const VIEW_TYPE = 'clx_map_navigation';
...@@ -12,19 +16,16 @@ class MethodChannelClxMapNavigation extends ClxMapNavigationPlatform { ...@@ -12,19 +16,16 @@ class MethodChannelClxMapNavigation extends ClxMapNavigationPlatform {
@visibleForTesting @visibleForTesting
final methodChannel = const MethodChannel('clx_map_navigation'); final methodChannel = const MethodChannel('clx_map_navigation');
@override MethodChannel channel() {
Future<String?> getPlatformVersion() async { return methodChannel;
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
} }
@override @override
Widget buildMapNavigationView( Widget buildMapNavigationView(
Map<String, dynamic> creationParams, Map<String, dynamic> creationParams,
Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers, Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers,
void Function(int id) onPlatformViewCreated) { void Function(int id) onPlatformViewCreated,
print("------MethodChannelClxMapNavigation: method=buildMapNavigationView"); MapClosedCallback? onMapClosed,) {
if (defaultTargetPlatform == TargetPlatform.android) { if (defaultTargetPlatform == TargetPlatform.android) {
creationParams['debugMode'] = kDebugMode; creationParams['debugMode'] = kDebugMode;
return AndroidView( return AndroidView(
...@@ -45,4 +46,20 @@ class MethodChannelClxMapNavigation extends ClxMapNavigationPlatform { ...@@ -45,4 +46,20 @@ class MethodChannelClxMapNavigation extends ClxMapNavigationPlatform {
} }
return Text('当前平台:$defaultTargetPlatform, 不支持使用高德地图插件'); return Text('当前平台:$defaultTargetPlatform, 不支持使用高德地图插件');
} }
// handleMethodCall的`broadcast`
final StreamController<MapEvent> _mapEventStreamController = StreamController<MapEvent>.broadcast();
StreamController<MapEvent> getMapEventStreamController() {
return _mapEventStreamController;
}
// 根据mapid返回相应的event.
Stream<MapEvent> _events() => _mapEventStreamController.stream;
// 底部退出回调
Stream<MapClosedEvent> onMapClosed() {
return _events().whereType<MapClosedEvent>();
}
} }
import 'package:clx_map_navigation/amap_navigation_widget.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -26,6 +27,10 @@ abstract class ClxMapNavigationPlatform extends PlatformInterface { ...@@ -26,6 +27,10 @@ abstract class ClxMapNavigationPlatform extends PlatformInterface {
_instance = instance; _instance = instance;
} }
Future<void> init() {
throw UnimplementedError('init() has not been implemented.');
}
// 获取平台版本实例 // 获取平台版本实例
Future<String?> getPlatformVersion() { Future<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.'); throw UnimplementedError('platformVersion() has not been implemented.');
...@@ -34,7 +39,8 @@ abstract class ClxMapNavigationPlatform extends PlatformInterface { ...@@ -34,7 +39,8 @@ abstract class ClxMapNavigationPlatform extends PlatformInterface {
Widget buildMapNavigationView( Widget buildMapNavigationView(
Map<String, dynamic> creationParams, Map<String, dynamic> creationParams,
Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers, Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers,
PlatformViewCreatedCallback onPlatformViewCreated) { PlatformViewCreatedCallback onPlatformViewCreated,
MapClosedCallback? onMapClosed,) {
throw UnimplementedError('buildView() has not been implemented.'); throw UnimplementedError('buildView() has not been implemented.');
} }
......
///地图事件处理
class MapEvent<T> {
///返回的内容,对应的[MethodCall]中的[[arguments]]
final T value;
/// 构造一个event
/// `value` 需要传输的值,可以为`null`.
MapEvent(this.value);
}
/// 底部退出按钮关闭回调接口
class MapClosedEvent extends MapEvent<String> {
MapClosedEvent(String value) : super(value);
}
...@@ -12,6 +12,7 @@ dependencies: ...@@ -12,6 +12,7 @@ dependencies:
sdk: flutter sdk: flutter
plugin_platform_interface: ^2.0.2 plugin_platform_interface: ^2.0.2
amap_flutter_base: ^3.0.0 amap_flutter_base: ^3.0.0
stream_transform: ^2.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
......
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:clx_map_navigation/core/clx_map_navigation.dart'; // import 'package:clx_map_navigation/core/clx_map_navigation.dart';
import 'package:clx_map_navigation/core/clx_map_navigation_platform_interface.dart'; import 'package:clx_map_navigation/core/clx_map_navigation_platform_interface.dart';
import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart'; import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart';
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论