3

How can I make GoogleMap to receive pointer events when it is wrapped by a GestureDetector, the following code prevents the map to be dragged:

GestureDetector(
    behavior: HitTestBehavior.translucent,
    onVerticalDragStart: _onMapDragged,
    onHorizontalDragStart: _onMapDragged,
    child: GoogleMap(...
Shady Aziza
  • 50,824
  • 20
  • 115
  • 113

1 Answers1

0

I think it may depend on what you need to do with that Gesture Detector.. I was having a similar problem using a GestureDetector to open/close a menu drawer. So my solution was to create a control variable to check if the Menu was opened or closed and then set null the event callbacks of the GestureDetector widget, something like this:

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onVerticalDragStart: isDraggable ? _doVerticalDrag : null,
  onHorizontalDragStart: isDraggable ? _doHorizontalDrag : null,
  child: GoogleMap(),
);

So when isDraggable is false the map will receive the drag actions.

Hope this helps to someone else having a similar problem.

damato
  • 185
  • 1
  • 6