Search code examples
google-mapsdartflutter

Google map in Flutter not responding to touch events


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

Widget structure for first one is

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

and for second screen it is

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.


Solution

  • 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()))
    );
    

    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.