Skip to content

[google_maps_flutter] Markers do not obey consumeTapEvents configuration #39868

Open

Description

@JamesMcIntosh

If you set Marker.consumeTapEvents I would expect the onTap handler not to be called. Currently the event is passed to onTap.

When setting consumeTapEvents to false for Polygons, Polylines, Circles etc. the click handler is not attached to the element, for markers there is no option to disable the click listener in the Google Maps implementation so the result needs to be filtered out in the marker click listener.

Both iOS and Android are affected.

Activity

  1. pedromassangocode commented on Apr 28, 2021

    @pedromassangocode

    Still reproducible on current version of the maps plugin.

    code sample
    import 'package:flutter/material.dart';
    import 'package:google_maps_flutter/google_maps_flutter.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MapsDemo(),
        );
      }
    }
    
    class MapsDemo extends StatefulWidget {
      @override
      State createState() => MapsDemoState();
    }
    
    class MapsDemoState extends State<MapsDemo> {
    
      GoogleMapController mapController;
      LatLng _position = LatLng(40.73215972821489, -73.980936957489);
      Set<Marker> markers = {};
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: GoogleMap(
              mapToolbarEnabled: false,
              initialCameraPosition: CameraPosition(target: _position, zoom: 15.0),
              cameraTargetBounds: CameraTargetBounds(new LatLngBounds(
                  northeast: LatLng(40.73215972821489, -73.980936957489),
                  southwest: LatLng(40.7152797683329, -74.01919598687743)
              )
              ),
              markers: markers,
              onTap: (_position) {
                markers.add(Marker(
                  markerId: MarkerId('m1'),
                  draggable: true,
                  position: _position,
                  consumeTapEvents: false,
                  onTap: () {
                    print("Called...");
                  },
                  icon: BitmapDescriptor.defaultMarkerWithHue(100),
                ));
                mapController.moveCamera(CameraUpdate.newLatLng(_position));
                setState(() {
    
                });
              },
              onMapCreated: (GoogleMapController controller) {
                mapController = controller;
              },
            ),
        );
      }
    }
  2. added
    P2Important issues not at the top of the work list
    on Jul 11, 2021
  3. added 4 commits that reference this issue on Feb 27, 2023
  4. nzkn commented on Aug 1, 2023

    @nzkn

    Not fixed in the latest version

  5. nzkn commented on Aug 1, 2023

    @nzkn
  6. jaween commented on Sep 21, 2023

    @jaween

    I believe this is working correctly, but it's just an odd api decision and confusing documentation. There's two tap handlers: the default handler which centers the map on the marker, and there's the user's custom onTap handler. To disable the default handler, set consumeTapEvents to true. To disable the user's handler, set onTap to null.

    This works for me on iOS to disable the centering on the marker with a custom tap handler, haven't tested Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 2.3Found to occur in 2.3has 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