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

提交:优化导航插件;

上级 bf7410aa
......@@ -25,7 +25,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AMapFoundation: f48153f724114b58da9b01875ab88a1f6856e3db
AMapNavi: 04727c06ec51fc4d7c57d83e2542da81b32f2f59
clx_map_navigation: 4eb146ec054cc72567c5b372d20ba4d0ed6ee365
clx_map_navigation: b73614901161608d76ebfe6ec266773bdfe00b26
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
......
......@@ -372,7 +372,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driverFlutter;
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driver;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
......@@ -496,7 +496,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driverFlutter;
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driver;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
......@@ -515,7 +515,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driverFlutter;
PRODUCT_BUNDLE_IDENTIFIER = com.clx.driver;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
......
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:clx_map_navigation_example/map_config.dart';
import 'package:flutter/material.dart';
import 'package:clx_map_navigation/amap_navigation_widget.dart';
import 'package:clx_map_navigation/core/clx_map_navigation.dart';
void main() {
runApp(const MyApp());
......@@ -30,10 +28,15 @@ class _MyAppState extends State<MyApp> {
),
body: const AMapNavigationWidget(
apiKey: AMapConfig.aMapApiKeys,
startPoint: { "latitude": 39.993135, "longitude": 116.474175 },
endPoint: { "latitude": 39.908791, "longitude": 116.321257 },
// startPoint: { "latitude": 39.993135, "longitude": 116.474175 },
// 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';
class AMapConfig {
static const androidKey = "8395ac94201590a0e5cfe4c836b1d2c9";
static const iosKey = "3d2ef3dd5e6da65e19e34d34d9a403a1";
static const iosKey = "3d2ef3dd5e6da65e19e34d34d9a403a1"; //com.clx.driver
static const AMapApiKey aMapApiKeys = AMapApiKey(
iosKey: iosKey,
androidKey: androidKey,
);
static onMapClosed() {
print("----- onMapClosed ---- 处理完了");
}
}
\ No newline at end of file
......@@ -156,6 +156,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: transitive
description:
......
......@@ -35,7 +35,8 @@
if (self = [super init]) {
NSAssert([args isKindOfClass:[NSDictionary class]], @"传参错误");
//构建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
binaryMessenger:registrar.messenger];
_viewId = viewId;
......@@ -240,6 +241,13 @@
[driveView removeFromSuperview];
[[AMapNaviDriveManager sharedInstance] stopNavi];
[[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 {
......
import 'dart:async';
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_platform_interface.dart';
import 'package:clx_map_navigation/core/map_event.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:flutter/services.dart';
final MethodChannelClxMapNavigation _methodChannel = ClxMapNavigationPlatform.instance as MethodChannelClxMapNavigation;
typedef void MapClosedCallback();
class AMapNavigationWidget extends StatefulWidget {
/// 高德开放平台的key
final AMapApiKey? apiKey;
/// 起点
final Map? startPoint;
/// 终点
final Map? endPoint;
///需要应用到地图上的手势集合
/// 需要应用到地图上的手势集合
final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers;
/// 导航地图底部退出的回调
final MapClosedCallback? onMapClosed;
const AMapNavigationWidget({
Key? key,
......@@ -28,6 +31,7 @@ class AMapNavigationWidget extends StatefulWidget {
required this.startPoint,
required this.endPoint,
this.gestureRecognizers = const <Factory<OneSequenceGestureRecognizer>>{},
this.onMapClosed,
}) : super(key: key);
@override
......@@ -35,9 +39,33 @@ class AMapNavigationWidget extends StatefulWidget {
}
class _MapNavigationState extends State<AMapNavigationWidget> {
@override
void 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
......@@ -52,6 +80,7 @@ class _MapNavigationState extends State<AMapNavigationWidget> {
creationParams,
widget.gestureRecognizers,
onPlatformViewCreated,
widget.onMapClosed,
);
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/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'clx_map_navigation_platform_interface.dart';
import 'package:stream_transform/stream_transform.dart';
const VIEW_TYPE = 'clx_map_navigation';
......@@ -12,19 +16,16 @@ class MethodChannelClxMapNavigation extends ClxMapNavigationPlatform {
@visibleForTesting
final methodChannel = const MethodChannel('clx_map_navigation');
@override
Future<String?> getPlatformVersion() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
MethodChannel channel() {
return methodChannel;
}
@override
Widget buildMapNavigationView(
Map<String, dynamic> creationParams,
Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers,
void Function(int id) onPlatformViewCreated) {
print("------MethodChannelClxMapNavigation: method=buildMapNavigationView");
void Function(int id) onPlatformViewCreated,
MapClosedCallback? onMapClosed,) {
if (defaultTargetPlatform == TargetPlatform.android) {
creationParams['debugMode'] = kDebugMode;
return AndroidView(
......@@ -45,4 +46,20 @@ class MethodChannelClxMapNavigation extends ClxMapNavigationPlatform {
}
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/gestures.dart';
import 'package:flutter/material.dart';
......@@ -26,6 +27,10 @@ abstract class ClxMapNavigationPlatform extends PlatformInterface {
_instance = instance;
}
Future<void> init() {
throw UnimplementedError('init() has not been implemented.');
}
// 获取平台版本实例
Future<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.');
......@@ -34,7 +39,8 @@ abstract class ClxMapNavigationPlatform extends PlatformInterface {
Widget buildMapNavigationView(
Map<String, dynamic> creationParams,
Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers,
PlatformViewCreatedCallback onPlatformViewCreated) {
PlatformViewCreatedCallback onPlatformViewCreated,
MapClosedCallback? onMapClosed,) {
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:
sdk: flutter
plugin_platform_interface: ^2.0.2
amap_flutter_base: ^3.0.0
stream_transform: ^2.0.0
dev_dependencies:
flutter_test:
......
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_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论