InfoWindow Size自适应便宜量
This commit is contained in:
parent
4b1a1326e8
commit
36518f3757
|
@ -28,7 +28,8 @@ class _State extends State<CustomInfoWindowDemoPage> {
|
||||||
color: Colors.lightBlue.shade400,
|
color: Colors.lightBlue.shade400,
|
||||||
child: Text('info'),
|
child: Text('info'),
|
||||||
),
|
),
|
||||||
option: InfoWindowOption(latLng: mapCenter));
|
option: InfoWindowOption(
|
||||||
|
latLng: mapCenter, offset: EdgeInsets.only(bottom: 32)));
|
||||||
|
|
||||||
Future<void> _onMapCreated(AMapController controller) async {}
|
Future<void> _onMapCreated(AMapController controller) async {}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ class _AMapLoaderState extends State<AMapLoader> {
|
||||||
buildContext: context,
|
buildContext: context,
|
||||||
currentStep: CurrentStep.preparing,
|
currentStep: CurrentStep.preparing,
|
||||||
loader: widget);
|
loader: widget);
|
||||||
|
|
||||||
widget.prepareFromExtension(aMapContext);
|
widget.prepareFromExtension(aMapContext);
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,6 @@ class _MapState extends State<AMapWidget> {
|
||||||
if (_extensions.isNotEmpty) {
|
if (_extensions.isNotEmpty) {
|
||||||
debugPrint('[onPlatformViewCreated] $controller');
|
debugPrint('[onPlatformViewCreated] $controller');
|
||||||
await Future.forEach(_extensions.values, (e) {
|
await Future.forEach(_extensions.values, (e) {
|
||||||
debugPrint('[onPlatformViewCreated] controller: ${controller.mapId}');
|
|
||||||
e.bindMethodChannel(controller.channel);
|
e.bindMethodChannel(controller.channel);
|
||||||
e.bindMapController(controller);
|
e.bindMapController(controller);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:amap_map/amap_map.dart';
|
import 'package:amap_map/amap_map.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:x_amap_base/x_amap_base.dart';
|
import 'package:x_amap_base/x_amap_base.dart';
|
||||||
|
|
||||||
/// [amap_map]插件支持默认的[InfoWindow]展示[title]和[snippet]字段,如果要自定义
|
/// [amap_map]插件支持默认的[InfoWindow]展示[title]和[snippet]字段,如果要自定义
|
||||||
|
@ -37,12 +37,13 @@ import 'package:x_amap_base/x_amap_base.dart';
|
||||||
class InfoWindowExtension extends AMapExtension {
|
class InfoWindowExtension extends AMapExtension {
|
||||||
InfoWindowExtension({required this.infoWindow, this.option});
|
InfoWindowExtension({required this.infoWindow, this.option});
|
||||||
|
|
||||||
StreamController<InfoWindowExtension> _streamController =
|
final _streamController = StreamController<InfoWindowExtension>.broadcast();
|
||||||
StreamController<InfoWindowExtension>.broadcast();
|
|
||||||
|
|
||||||
final Widget infoWindow;
|
final Widget infoWindow;
|
||||||
InfoWindowOption? option;
|
InfoWindowOption? option;
|
||||||
|
|
||||||
|
final GlobalKey _infoWindowKey = GlobalKey();
|
||||||
|
|
||||||
AMapController? mapController;
|
AMapController? mapController;
|
||||||
double? _x;
|
double? _x;
|
||||||
double? _y;
|
double? _y;
|
||||||
|
@ -67,6 +68,12 @@ class InfoWindowExtension extends AMapExtension {
|
||||||
_x = coordinate.x.toDouble();
|
_x = coordinate.x.toDouble();
|
||||||
_y = coordinate.y.toDouble();
|
_y = coordinate.y.toDouble();
|
||||||
|
|
||||||
|
final size = _infoWindowKey.currentContext?.size;
|
||||||
|
if (size != null && _x != null && _y != null) {
|
||||||
|
_x = _x! - size.width / 2;
|
||||||
|
_y = _y! - size.height;
|
||||||
|
}
|
||||||
|
|
||||||
_streamController.add(this);
|
_streamController.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +86,10 @@ class InfoWindowExtension extends AMapExtension {
|
||||||
@override
|
@override
|
||||||
Widget build(AMapContext aMapContext, Widget child) {
|
Widget build(AMapContext aMapContext, Widget child) {
|
||||||
return Stack(
|
return Stack(
|
||||||
|
key: ValueKey(this),
|
||||||
children: [
|
children: [
|
||||||
child,
|
child,
|
||||||
StreamBuilder<InfoWindowExtension>(
|
StreamBuilder<InfoWindowExtension>(
|
||||||
key: ValueKey(this),
|
|
||||||
initialData: this,
|
initialData: this,
|
||||||
stream: _streamController.stream,
|
stream: _streamController.stream,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
|
@ -97,6 +104,7 @@ class InfoWindowExtension extends AMapExtension {
|
||||||
top: data._y,
|
top: data._y,
|
||||||
left: data._x,
|
left: data._x,
|
||||||
child: Container(
|
child: Container(
|
||||||
|
key: _infoWindowKey,
|
||||||
margin: data.option?.offset,
|
margin: data.option?.offset,
|
||||||
child: infoWindow,
|
child: infoWindow,
|
||||||
),
|
),
|
||||||
|
@ -105,6 +113,12 @@ class InfoWindowExtension extends AMapExtension {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onDispose() {
|
||||||
|
_streamController.close();
|
||||||
|
super.onDispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InfoWindowOption {
|
class InfoWindowOption {
|
||||||
|
|
Loading…
Reference in New Issue