问题描述
在问候您的同时,我想问您是否有人能够在扑动的地图制作器中显示一个信息窗口,或者是否创建了一个浮动的容器,以便使其出现在制作者的旁边,如果可能,它会出现在Google地图中。
new Marker
(
width: 45.0,height: 45.0,point: new LatLng(-25.963678,-51.240657),builder: (ctx) =>
new Container //here infoWindow or Float Container
(
//child: new Flutterlogo(),child: IconButton
(
icon: Icon(Icons.location_on),color: Colors.blue,iconSize: 45.0,tooltip: "prueba",onpressed: ()
{
print("test press");
},)
),),
非常感谢您一如既往的帮助。
解决方法
您无法在任何Flutter Map插件中将小部件设置为标记信息窗口。您只能在Google Maps插件中设置信息窗口的标题和文本。
您可以关闭地图信息窗口,如果用户单击它,则将地图置于标记的中心,并添加一些代码以在屏幕的大致中心显示自定义对话框。您将必须使用flutter的Stack小部件。
Stack(
children:[
Map(
markers: [Marker(/*no info-window*/,onTap: (){
setState((){ _opacity = 1; });
})],onMapMove: (){
setState((){ _opacity = 0; });
}
),Opacity(
opacity: _opacity,child: /*custom info-window*/,),],mainAxisAlignment: MainAxisAlignment.center,crossAxisAlignment: CrossAxisAlignment.center,
,
使用 custom_info_window 包如下:
步骤 1:初始化 CustomInfoWindowController。
CustomInfoWindowController _customInfoWindowController = CustomInfoWindowController();
第 2 步:从标记的 onTap 函数调用 CustomInfoWindowController 的 addInfoWindow。
Marker(
markerId: MarkerId("marker_id"),position: _latLng,onTap: () {
_customInfoWindowController.addInfoWindow(
<YOUR CUSTOM WIDGET>,_latLng,);
},)
第 3 步:将 GoogleMap Widget 与 Stack 结合使用。
Stack(
children: <Widget>[
GoogleMap(
onTap: (position) {
_customInfoWindowController.hideInfoWindow();
},onCameraMove: (position) {
_customInfoWindowController.onCameraMove();
},onMapCreated: (GoogleMapController controller) async {
_customInfoWindowController.googleMapController = controller;
},markers: _markers,initialCameraPosition: CameraPosition(
target: _latLng,zoom: _zoom,CustomInfoWindow(
controller: _customInfoWindowController,height: 75,width: 150,offset: 50,)
调用_customInfoWindowController.hideInfoWindow();在 GoogleMap 的 onTap 内点击地图而不是标记时隐藏 CustomInfoWindow。
调用_customInfoWindowController.onCameraMove();保持 CustomInfoWindow 相对于标记的位置。 [重要]
分配 _customInfoWindowController.googleMapController = 控制器;在 onMapCreated 里面。 [重要]
将 CustomInfoWindow 添加为下一个子项,使其在 GoogleMap 顶部浮动。