|
|
@@ -2,6 +2,8 @@ import 'dart:convert';
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
+import 'package:flutter/gestures.dart';
|
|
|
+import 'package:flutter/rendering.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:flutter_map/src/consts/map_constants.dart';
|
|
|
import 'package:flutter_map/src/consts/marker_type.dart';
|
|
|
@@ -30,11 +32,16 @@ class _MapWidgetState extends State<MapWidget> {
|
|
|
debugPrint(
|
|
|
'MapWidget...build...mapViewType==>$mapViewType,defaultTargetPlatform==>$defaultTargetPlatform');
|
|
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
|
|
- return AndroidView(
|
|
|
- viewType: mapViewType,
|
|
|
- onPlatformViewCreated: onPlatformViewCreated,
|
|
|
- creationParamsCodec: const StandardMessageCodec(),
|
|
|
- );
|
|
|
+ return PlatformViewLink(
|
|
|
+ surfaceFactory: (context, controller) {
|
|
|
+ return AndroidViewSurface(
|
|
|
+ controller: controller as AndroidViewController,
|
|
|
+ gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
|
|
|
+ hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
|
|
+ );
|
|
|
+ },
|
|
|
+ onCreatePlatformView: onCreatePlatformView,
|
|
|
+ viewType: mapViewType);
|
|
|
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
|
|
return UiKitView(
|
|
|
viewType: mapViewType,
|
|
|
@@ -45,6 +52,23 @@ class _MapWidgetState extends State<MapWidget> {
|
|
|
return Text('当前平台:$defaultTargetPlatform, 不支持使用地图插件');
|
|
|
}
|
|
|
|
|
|
+ PlatformViewController onCreatePlatformView(
|
|
|
+ PlatformViewCreationParams params) {
|
|
|
+ MethodChannel mapChannel =
|
|
|
+ MethodChannel('${MapConstants.mapViewChannelName}${params.id}');
|
|
|
+ widget.controller?.setChannel(mapChannel);
|
|
|
+ mapChannel.setMethodCallHandler(_mapMethodCallHandler);
|
|
|
+ return PlatformViewsService.initSurfaceAndroidView(
|
|
|
+ id: params.id,
|
|
|
+ viewType: mapViewType,
|
|
|
+ layoutDirection: TextDirection.ltr,
|
|
|
+ creationParams: <String, dynamic>{},
|
|
|
+ creationParamsCodec: const StandardMessageCodec(),
|
|
|
+ )
|
|
|
+ ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
|
|
|
+ ..create();
|
|
|
+ }
|
|
|
+
|
|
|
Future<void> onPlatformViewCreated(int viewId) async {
|
|
|
MethodChannel mapChannel =
|
|
|
MethodChannel('${MapConstants.mapViewChannelName}$viewId');
|