-
-
Notifications
You must be signed in to change notification settings - Fork 868
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
RangeError in marker optimization code #887
Comments
Damn, I was afraid that some RandeErrors will come up after messing with lists like that... I will take a look 👍 |
Okay, so I see that: Markers aren't really touched anywhere on those pages, and Then, inside `LayerOptions you have them as mutable: Then, you add them in which also changes the Anyway, it looks that the way of adding markers in this plugin is not Flutter-ish at all, at leat to me 🤔 - because of that, We can do two things:
|
Dear @TheLastGimbus Thanks for you analysis.
Good catch. I can easily change it to
It adds/removes elements from the
I would be open for changes 🙂 What is your recommended change here? In general the task: If the user clicks a "get my location" button show the location as marker on the map. |
Hmm... in my opinion - remove class _PageState extends State<Page> {
final myMarkers = [marker1, marker2];
// Idk if your library can give multiple markers or just one
var locationMarkers = <Marker>[];
Widget build() {
// ...
body: Center(
child: FlutterMap(
// ...
mapController: mapController,
options: MapOptions(
plugins: <MapPlugin>[LocationPlugin()],
),
layers: <LayerOptions>[
MarkerLayerOptions(markers: myMarkers + locationMarkers),
LocationOptions(
onLocationUpdate: (LatLngData ld, List<Marker> markers) {
locationMarkers = makrers;
setState(() {});
},
),
],
),
),
}
} Something like this 🤷 |
Thanks a lot you. I'll look into it. Still might be worth to fix that introduce regression in flutter_map itself if it's possible to run into it. I would guess other plugins are affected as well. For example user_location_layer that use a similar pattern that the |
😬This should not be like this in my opinion... I can add a quick-fix-lenght-check if you want, but honestly I feel like this should throw an error - to show other plugin makers that they can't do it this way... |
At least for the flutter_map_location plugin it's fixed now. The development branch was successfully updated in Xennis/flutter_map_location#51 (The actual work was done Xennis/flutter_map_location#48 ). |
I run into this in my own code. Any advice how to avoid this? |
I think above discussion should help you - basically don't mutate stuff - all arguments to |
Would that mean fully rerendering the entire map including tiles each time there is a change to the markers is a necessity? Just for reference: We hit this error when trying to add markers after fetching information from the server. We tried to achieve that by having an empty array, populating it with the network response and using the rebuild Stream to update the layer which in turn caused the issue at hand. |
Yea same thing for me, not sure how this discussion helps me :( |
Just wondering if generatePxCache() could be called if the pxcache list length is a different length to the markerlist ? |
Yes, altought this shouldn't be a problem. You can probably call |
Wonderful, thanks a bunch! |
My problem was setState(() {
markers = [
...markers,
addNewMarker(),
];
}); |
Dear @TheLastGimbus thanks for adding #826 . I'm one of the maintainer of a flutter_map plugin. I'm getting at
flutter_map/lib/src/layer/marker_layer.dart
Line 214 in 38d9047
the following error:
The issue can be reproduce with the example here https://github.com/Xennis/flutter_map_location/tree/pxcache-issue/example
Can you please take a look?
The text was updated successfully, but these errors were encountered: