Gesture detector on flutter_map don't work

208 Views Asked by At

On flutter_map I add a custom marker in marker layer. Wrap the builder of the marker widget with a gesturedetector expecting detect a tap over the marker. Did not detect nothing

The flutter map is in stack widget and the onTap option of flutter_map MapOptions works fine.

return Scaffold(
  body: Container(
    child: 

      FlutterMap(
          options: MapOptions(
          center: LatLng(_currentPosition!.latitude, _currentPosition!.longitude),
          zoom: 15,
          interactiveFlags: InteractiveFlag.all,
        ),
        mapController: _mapController,
        children: [
          TileLayer(
              urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
              userAgentPackageName: 'com.example.app',
          ),
          MarkerLayer(
            markers: [
              Marker(
                point: LatLng(_currentPosition!.latitude, _currentPosition!.longitude),
                width: 35,
                height: 35,
                builder: (context) => GestureDetector(
                  onTap: () {
                    print("tap on start");
                  },
                  child:IgnorePointer(
                      child: Container(
                        decoration: const BoxDecoration(
                          color: Color.fromARGB(255, 3, 101, 6),
                          shape:BoxShape.circle,
                        ),
                        child: const Icon(
                          color: Colors.white,
                          Icons.pin_drop_rounded,
                          ),
                        
                      ),
                    ),
                )
            )
            ]
          ),
           //MapsMarkerLayer(initialLocation: LatLng(_currentPosition!.latitude, _currentPosition!.longitude),markerPosition: deliveryMarkers),
           mapsPolylines(jobId: widget.jobId)
        ],
      ),
    
  ),
);
2

There are 2 best solutions below

1
DholaSain On

Wrap your Marker with the IgnorePointer widget, and then wrap the IgnorePointer with GestureDetector.

Learn more about it from this official tutorial. IgnorePointer class

0
Vladimir Roldan On

The problem is not in the code. The problem is that uppers layers block interaction of the previous ones. So i put the marker layer as the last one and it works.. Thanks a lot to all..