我是flutter的開發者,我想做一個簡單的地圖應用,其中有一些功能,當我點擊標記時,顯示我的自定義視窗,再點擊標記時,隱藏自定義視窗。
此刻,當點擊標記時,只顯示自定義視窗,但不隱藏自定義視窗。
我的源代碼詳情如下:
import 'package:clippy_flutter/triangle.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:custom_info_window/custom_info_window.dart';
class CustomInfoWindowF extends StatefulWidget{
@override
_CustomInfoWindowExampleState createState() =>
_CustomInfoWindowExampleState()。
}
class _CustomInfoWindowExampleState extends State< CustomInfoWindowF> {
CustomInfoWindowController _customInfoWindowController =自定義資訊視窗控制器。
CustomInfoWindowController()。
final LatLng _latLng = LatLng(28.7041, 77.1025)。
final double _zoom = 15.0;
@override
void dispose() {
_customInfoWindowController.dispose()。
super.dispose()。
}
Set<Marker> _markers = {};
@override
Widget build(BuildContext context) {
_markers.add(
標記(
markerId: MarkerId("marker_id")。
位置。_latLng,
onTap: () {
_customInfoWindowController.addInfoWindow(
列(
兒童。[
擴展的(
child: 容器(
裝飾。BoxDecoration(
color: Colors.blue,
borderRadius: borderRadius.round(4)。
),
孩子。Padding(
padding: const EdgeInsets.all(8.0)。
兒童。列(
兒童。[
行(
mainAxisAlignment: MainAxisAlignment.center,
children: [
圖示(
Icons.account_circle,
color: Colors.white,
大小。30。
),
SizedBox(
width: 8.0,
),
文本(
"我在這里"。
風格。
Theme.of(context).textTheme.headline6.copyWith(
color: Colors.white,
),
)
],
),
],
),
),
width: double.無限大。
高度。double.infinity。
),
),
Triangle.isosceles(
邊緣。Edge.BOTTOM,
孩子。容器(
color: Colors.blue,
width: 20.0,
高度。10.0。
),
),
],
),
_latLng,
);
},
),
);
return Scaffold(
appBar: AppBar(
標題。Text('Custom Info Window Example')。
backgroundColor: Colors.red,
),
body: 堆疊(
children: <Widget>[
谷歌地圖(
onTap: (position) {
_customInfoWindowController.hideInfoWindow()。
},
onCameraMove: (position) {
_customInfoWindowController.onCameraMove()。
},
onMapCreated: (GoogleMapController控制器) async {
_customInfoWindowController.googleMapController = controller;
},
標記。_markers,
initialCameraPosition: CameraPosition()
目標。_latLng,
zoom: _zoom,
),
),
CustomInfoWindow(
控制器。_customInfoWindowController,
高度。175,
width: 250,
偏移量。50,
),
],
),
);
}
}
我的pubspec.yaml依賴檔案源代碼如下
google_maps_flutter。^2.0.6。
custom_info_window: ^1.0.1
clippy_flutter: ^1.1.1
uj5u.com熱心網友回復:
在我的CustomInfoWindow中創建一個按鈕,然后onPress 呼叫
_customInfoWindowController.hideInfoWindow()。
它將被解決。 謝謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/328615.html
標籤:
