Skip to content

GoogleMaps and GestureDetector don't play well together #59433

@mlemos

Description

@mlemos

In my app I have a GoogleMap widget that is the child of a GestureDetector widget.
I need to set a variable every time the user moves the map (pan, scale, etc) and I'm using the GestureDetector for that. Also, I need the map to simultaneously receive the gestures, in order the be interactive.

My code kind of works, but it is not responsible or reliable on scale (pinch) gestures. Sometimes the events are handled by the map and other times they aren't. Pan events (drag with one finger) are handled just fine.

Any idea on that is causing this behavior?

Here is the code...

return Scaffold(
  body: GestureDetector(
    onPanStart: (val) {
      Logger.red("Parent: I'm panning...");
      _followPosition = false;
    },
    behavior: HitTestBehavior.opaque,
    child: GoogleMap(
      gestureRecognizers: [
        Factory<PanGestureRecognizer>(() => PanGestureRecognizer()),
        Factory<ScaleGestureRecognizer>(() => ScaleGestureRecognizer()),
      ].toSet(),
      initialCameraPosition: _cameraPosition,
      onMapCreated: (GoogleMapController controller) =>
          _handleMapCreated(controller),
      onCameraMove: (CameraPosition cameraPosition) =>
          _handleCameraMove(cameraPosition),
      onCameraIdle: () => _handleCameraIdle(),
    ),
  ),
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: platform-viewsEmbedding Android/iOS views in Flutter appsf: gesturesflutter/packages/flutter/gestures repository.found in release: 2.3Found to occur in 2.3frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions