Flutter 中的谷歌地图没有响应触摸事件 [英] Google map in Flutter not responding to touch events
问题描述
我在 Flutter 应用中有两个不同的屏幕,它们使用 Google 地图(由这个 图书馆 提供).
I got two different screens inside Flutter app that use Google Map (provided by this library).
第一个小部件结构是
Scaffold -> ListView -> Visibility -> Center -> SizedBox -> GoogleMap
Scaffold -> ListView -> Visibility -> Center -> SizedBox -> GoogleMap
第二个屏幕是
Scaffold -> Container -> Column -> SizedBox -> GoogleMap
Scaffold -> Container -> Column -> SizedBox -> GoogleMap
在两个屏幕上我得到了相同的地图设置,但由于某种原因,第一个屏幕地图没有响应任何触摸事件.
On both screens I got same map settings but for some reason on the first screen map is not responding to any touch events.
推荐答案
您需要通过设置 gestureRecognizers
来告诉 GoogleMap
小部件您希望它响应哪些手势属性,类似这样:
You need to tell the GoogleMap
widget which gestures you want it to respond to by setting the gestureRecognizers
property, something like this:
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
...
GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(0, 0),
),
gestureRecognizers: Set()
..add(Factory<PanGestureRecognizer>(() => PanGestureRecognizer()))
);
这不是特定于 GoogleMap
小部件的,您需要对任何在幕后使用 AndroidView
/UIKitView
的小部件执行此操作处理放置在可滚动视图中的手势.
This is not specific to the GoogleMap
widget, you would need to do this with any widget that uses AndroidView
/UIKitView
under the covers to handle gestures when it's placed inside a scrollable view.
这篇关于Flutter 中的谷歌地图没有响应触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!