Change request to followOnLocationUpdate
dfrobese opened this issue · 3 comments
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.
I don't think there is another way to handle map moving in flutter_map.🤔
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?
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.