tlserver / flutter_map_location_marker

A flutter map plugin for displaying device current location.
https://pub.dev/packages/flutter_map_location_marker
BSD 3-Clause "New" or "Revised" License
97 stars 81 forks source link

Change request to followOnLocationUpdate #60

Closed dfrobese closed 1 year ago

dfrobese commented 1 year ago

Hi, can you make the mode editable without rebuilding the whole FlutterMap child stack?

I want to switch between the modes without rebuilding always the child stack. The example follow_fab_example.dart is very resource consuming when you follow the approach in an real app.

tlserver commented 1 year ago

I don't think there is another way to handle map moving in flutter_map.🤔

dfrobese commented 1 year ago

When you send a zoom request via the stream _followCurrentLocationStreamController.add(_mapController.zoom) it relocates as well without calling setState() and rebuilding all the map stack. it is much more efficient. In your example the setState() and subsequent build() calls are initiated on every gesture Why not make followOnLocationUpdate as a variable changeable?

tlserver commented 1 year ago

Ok, I see what you mean. I think the problem you meantioned is that every guesture cause the widget calling setState(). It can be solved by adding a check before calling setState().

          // Stop following the location marker on the map if user interacted with the map.
          onPositionChanged: (MapPosition position, bool hasGesture) {
            if (hasGesture && _followOnLocationUpdate != FollowOnLocationUpdate.never) {
              setState(
                () => _followOnLocationUpdate = FollowOnLocationUpdate.never,
              );
            }
          },

I think it is overhead if CurrentLocationLayer use Stream<FollowOnLocationUpdate> to receive parameters because the frequency of changing followOnLocationUpdate is not high. But if you really care about that the whole map rebuild caused by updating followOnLocationUpdate, you can warp the CurrentLocationLayer in to a StreamBuilder and create a StreamController<FollowOnLocationUpdate> yourself.