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

[BUG] Polygons and Polylines don't update when points modified #1894

Closed
tologonkudaiberdiuulu opened this issue May 28, 2024 · 5 comments · Fixed by #1904
Closed

[BUG] Polygons and Polylines don't update when points modified #1894

tologonkudaiberdiuulu opened this issue May 28, 2024 · 5 comments · Fixed by #1904
Labels
bug This issue reports broken functionality or another error P: 1 (important) S: core Scoped to the core flutter_map functionality

Comments

@tologonkudaiberdiuulu
Copy link

What is the bug?

After adding new points to polygon, it's not updating automatically. You should explicitly add UniqueKey to Polygon widget.

How can we reproduce it?

To reproduce you can view min sample in github. To solve you can uncomment "// key: UniqueKey()," part in map_page.dart file

Do you have a potential solution?

No

Platforms

All

Severity

Obtrusive: Prevents normal functioning but causes no errors in the console

@tologonkudaiberdiuulu tologonkudaiberdiuulu added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels May 28, 2024
@JaffaKetchup JaffaKetchup added P: 1 (important) S: core Scoped to the core flutter_map functionality and removed needs triage This new bug report needs reproducing and prioritizing labels May 28, 2024
@JaffaKetchup
Copy link
Member

This issue is occuring because the equality checking for elements is not working correctly.
A temporary workaround is shown in the invalid issue flutter/flutter#106743: use List.from to create a new list instance.

@tologonkudaiberdiuulu
Copy link
Author

tologonkudaiberdiuulu commented May 28, 2024

Then maybe when overriding "=" operator of Polygon object, you should check manually? Not using listEquals function.

@JaffaKetchup
Copy link
Member

It's not due to that. Its because the list instance is shared, so the list on the oldWidget and newwidget are always the same.

@tologonkudaiberdiuulu
Copy link
Author

tologonkudaiberdiuulu commented May 28, 2024

I already tried to make like this
image

It's also not working. Only way to work is creating "mapsPolygons" variable also from new instance of List.
Like this:
image

But it's too complicated, no?

@JaffaKetchup
Copy link
Member

I generally wouldn't recommend doing what you're doing. Instead, use List<List<LatLng>>.map((coords) {}).toList() on the coordinates list, in the build method. This may also resolve the issue as well.

final coordinates = <List<LatLng>>[...];

// inside `build`
PolygonLayer(
	polygons: coordinates.map((c) => Polygon(points: c)).toList(),
),

@JaffaKetchup JaffaKetchup changed the title Polygons not updating [BUG] Polygons and Polylines don't update when points modified Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error P: 1 (important) S: core Scoped to the core flutter_map functionality
Projects
None yet
2 participants