flutter_map
flutter_map copied to clipboard
[BUG] Markers not displaying on first map display (map doesn't have a size on certain devices).
What is the bug?
When you look at the example HomePage, there should be 3 markers. Only one displays until you move the map.
(This works fine on the web, but not on some devices, tested on Android Redmi Note 10).
What is the expected behaviour?
All 3 markers should appear.
How can we reproduce this issue?
Just run the example home page.
Do you have a potential solution?
This is the likely issue.
When we run the marker_layer code, we do the following, to try and eliminate drawing markers out of bounds.
if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) {
continue;
}
However, if we look at the bounds, they are Bounds(CustomPoint (4093.0, 2724.0), CustomPoint (4093.0, 2724.0)) , so one pixel wide. So the markers get rejected apart from the one placed in the middle coincidentally.
The reason for that, is that in map.dart we call getPixelBounds()
Bounds getPixelBounds(double zoom) {
final mapZoom = zoom;
final scale = getZoomScale(mapZoom, zoom);
final pixelCenter = project(center, zoom).floor();
final halfSize = size / (scale * 2);
return Bounds(pixelCenter - halfSize, pixelCenter + halfSize);
}
And here, on first run it has a size of (0.0, 0.0)
So basically any code that calls things like pixelBounds.containsPartialBounds() won't work if it hasn't had chance to get a size (I think this is because the LayoutBuilder in flutter_map_state.dart context/constraints also has no size then, and even things like WidgetsBinding.instance.window.physicalSize returns 0,0).
There's probably some other subtle bugs all around this on first display.
Not sure of the best solution on this, as we've been here before. Maybe we should force FlutterMap to run 2 passes first time around, but then will it draw something wrong on the first pass, then right on the 2nd. Not quite sure of an elegant solution to this one (but there is some possibly boiler plate code that could be removed if we did).
Or possibly something like place it in an Offstage widget that doesn't draw first pass, then move it into view (could actually be a feature to make FlutterMap visible or not ? Not sure, just thinking out loud).
Can you provide any other information?
No response
Platforms Affected
Android
Severity
Minimum: Allows normal functioning
Frequency
Consistently: Always occurs at the same time and location
Requirements
- [X] I agree to follow this project's Code of Conduct
- [X] My Flutter/Dart installation is unaltered, and
flutter doctorfinds no relevant issues - [X] I am using the latest stable version of this package
- [X] I have checked the FAQs section on the documentation website
- [X] I have checked for similar issues which may be duplicates
Also can reproduce on my Redmi Note 10 Pro (what are the chances of that!).
I have been working on rewriting the state management and now have flutter_map correctly initializing the map variables (other than buildconstraints on initState and the first build correctly gets constraints before building children. This also has the added benefit of not needing variables to be nullable.
does #1333 fix this for you?
I CANNOT replicate using flutter_map-2.2.0
Yes, this seems to work ok with latest proposed changes, nice!
Can't find anything worse off (there's just a line 194 print("Skipping due to bounds"); in the marker_layer code that slows down panning slightly on Many Markers, I assume that can just be removed though)
yeah I left the print in on accident. it's removed now. I will mark the pr as closing.