flutter_map_dragmarker
flutter_map_dragmarker copied to clipboard
Programmatically update the location of a marker that already exists
As far as I can tell, you can't update the position of a marker that already exists. Is this correct? If so, I'll try to implement it in a good way and make a PR.
lets say I've dragged a marker to position X and you want to move it programmatically to position Y or something (without dragging it?)
Yeah I wasn't very clear but that's what I mean. In my case, I want the user to be able to type an address to update the location of a marker, so I just need some way of programmatically updating the position of a marker.
Interestingly enough, prior to the last couple of changes, you could kind of do this (as dragMarkers point internally was the same, however, this caused a problem where if you called setState it would reset the marker, so it was changed so that initState set up the point internally (var markerPoint in the code), so it would be preserved across setState).
However, that also conflicted with my line_editor plugin, which was kind of annoying, so I was initially wondering about having 2 options, 1) it preserves state (see line 79 markerPoint = widget.marker.point
previously it was all just widget.marker.point). and 2 it just references widget.marker.point internally, depending upon some argument.
It maybe depends a bit on whether one wants to not preserve state at all (what do you want to happen with a setState call), or just dynamically update it adhoc (but preserve state apart from that), or preserve it all the time.
Not sure if that's clear as mud!
Either would certainly work, but I think that the current behavior where it preserves state is actually pretty valuable; it was also what I assumed the behavior would be from the start. I could definitely see having an option that lets you switch between the two, although it would be unfortunate to have to lose the preservation of state if you want to be able to update it.
I was thinking, maybe there could be an optional Key parameter for DragMarker
s that would be passed through to the associated DragMarkerWidget
. This would allow users to force Flutter to update the widget (technically create a new one) just by changing the key for the marker they want to update. However, I suppose that passing through a Key could be considered exposing an implementation detail.