Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically update the location of a marker that already exists #21

Open
invpt opened this issue Sep 13, 2022 · 4 comments · May be fixed by #22
Open

Programmatically update the location of a marker that already exists #21

invpt opened this issue Sep 13, 2022 · 4 comments · May be fixed by #22

Comments

@invpt
Copy link

invpt commented Sep 13, 2022

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.

@ibrierley
Copy link
Owner

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

@invpt
Copy link
Author

invpt commented Sep 13, 2022

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 invpt changed the title Update the location of a marker that already exists Programmatically update the location of a marker that already exists Sep 13, 2022
@ibrierley
Copy link
Owner

ibrierley commented Sep 13, 2022

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!

@invpt
Copy link
Author

invpt commented Sep 13, 2022

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 invpt linked a pull request Sep 13, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants