Flutter中的Google地图未响应触摸事件 [英] Google map in Flutter not responding to touch events

查看:191
本文介绍了Flutter中的Google地图未响应触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Flutter应用程序中,我有两个使用Google Map的屏幕(由图书馆提供) 。

I got two different screens inside Flutter app that use Google Map (provided by this library).

第一个窗口小部件的结构是

Widget structure for first one is


脚手架-> ListView->可见性->中心-> SizedBox-> GoogleMap

Scaffold -> ListView -> Visibility -> Center -> SizedBox -> GoogleMap

第二屏为


脚手架->容器->列-> 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中的Google地图未响应触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆