-
-
Notifications
You must be signed in to change notification settings - Fork 860
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] External MapController
lifecycle not synced with widget when destroyed and rebuilt
#1892
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Well it worked with version 6.1.0, but broke with 7.0.0. Tested with a production build: the map disappears, and there is an exception in the log:
|
That is something we weren't expecting to see. I wasn't aware that anything had changed in that area of the code. |
@Zverik I noticed you're initialising your map controller within the |
Alas no, it's declared outside any of methods :( Would be an easy fix! |
Ah, misread the indentation. The only way this can occur is when the |
I'm thinking this was introduced in #1738. It made the most changes to this area between v6 and v7. |
So I took the When I comment out the mapController assignment, it works. |
I frankly do not understand the nature of changes in |
@Zverik As a short term workaround, try setting |
Yes, that works, thank you Luka! |
MapController
lifecycle not synced with widget when destroyed and rebuilt
Similar issue was reported on Discord, but with tabs instead of list items. |
I've run into a similar issue that cannot be resolved by |
@JaffaKetchup What is the expected behavior here? At the moment a MapController is not meant to be a global map state and can only get attached to a map widget once. This behavior should be the same in v6 and in v7. This means that the MapController is only meant to be kept as long as the map widget exists. |
Note that a map controller can be created in a containing stateful widget, being a part of its state. |
As @Zverik said, this isn't always easy and/or possible. You'd need to create a layer to export the map controller on every build from the inherited state I guess. Is there a reason why being able to reassign wouldn't work? (Also moving this to P2 as the workaround seems to work fine). |
Not really, should be doable. It just wasn't designed that way in the past. Could be that it was a problem with the cyclic dependency of the map controller but that got removed in #1738. |
We have the same problem when using the global map controller. |
I'd probably take a look at an Offstage widget to put the map in (and possibly move it offstage from the listview when outside the displayed widgets if it doesn't keep its state at that point still). |
@FeofanGreek Could you give more information about the 3rd party application you are using? |
I didn’t express myself correctly about the “Application”, of course we use functions inside our application, but launched in the background. However, the functions themselves require simple controller-based transformations. And it is not always possible to gain access through the instance of the screen on which the map is displayed.
|
I have implemented the following function to recreate MapController and MapOptions each time FlutterMap is rerendered, but it still throws the error in described in OP:
Even though |
You can try to use the pull request #1915 to see if works with it. dependency_overrides:
flutter_map:
git:
url: https://github.com/josxha/flutter_map
ref: feat/assign-controller-to-map-widget-multiple-times |
Hooray! Everything worked |
The fix by @josxha works. If anyone encounters the issue of Polygons not updating, the fix is to give new |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Please also double check https://docs.fleaflet.dev/usage/programmatic-interaction/external-custom-controllers#usage-within-a-state-system-model if using external state. |
I have the similar issue. I have the stateful widget with the map and refresh buttom that suppose to bring map to initial position with tha mapController defined on the state widget level. After updating 6.0.1 -> 7.0.1 I'm getting an error when that button is pressed and the setState initiated.
To eliminate the issue I've removed [final] from _interactiveViewerState declaration. This solved the error. But, comparing to 6.0.1, 7.0.1 widget dont automaticaly catch the new initial LatLon during redrawing, so I have to manually add controller move after each location change
|
What is the bug?
I have a FlutterMap in a ListView. It displays fine. When I scroll down so the map is not visible (and the state is lost), and then scroll back up, the map is broken (at least in the debug build), and there is an assertion in the console: "Should not update options unless they change", originating from
map_controller_impl.dart:342
.I guess the widget gets deleted when not in view, then built again, and the same mapController gets reattached. Is that correct?
How can we reproduce it?
Sorry I don't have a short code at hand, my laptop acts up. I encountered this when running Every Door: find a POI and tap on it, and then scroll down, opening "more fields", to the bottom. And then up. Here is how the object created.
Do you have a potential solution?
Remove the assertion?..
Platforms
Android 14 (Sony Xperia 10 IV).
Severity
Erroneous: Prevents normal functioning and causes errors in the console
The text was updated successfully, but these errors were encountered: