flutterfluttermap

I flutter_map, how to handle map dragged away from user marker?


I use a combination of flutter_map and flutter_map_location_marker. flutter_map_location_marker Lets me display a marker corresponding to the user's position, and orientation. It lets me also center the map automatically around the user's current position.

I would like however to stop the user tracking feature if the user pans the map around.

But both the user location changing, and map dragging end up triggering the same onPositionChanged event. I don't see a way to discern wether that event was due to panning or location update.

How could I discern both?

I have tried wrapping FlutterMap with a GestureDetector, but it does not catch map panning events, so I cannot snoop user actions.

Thanks in advance!


Solution

  • You should be able to use the hasGesture parameter passed to the onPositionChanged callback to discern between user gesture and map controller/plugin.

    Note that the "Follow FAB" example in their repository has this functionality: https://github.com/tlserver/flutter_map_location_marker/blob/master/example/lib/page/follow_fab_example.dart.