flutter_map_dragmarker icon indicating copy to clipboard operation
flutter_map_dragmarker copied to clipboard

Programmatically update the location of a marker that already exists

Open invpt opened this issue 2 years ago • 4 comments

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.

invpt avatar Sep 13 '22 15:09 invpt

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?)

ibrierley avatar Sep 13 '22 15:09 ibrierley

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.

invpt avatar Sep 13 '22 15:09 invpt

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!

ibrierley avatar Sep 13 '22 15:09 ibrierley

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 DragMarkers 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.

invpt avatar Sep 13 '22 16:09 invpt