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

fix for flickering with fitbounds, moving calculations inside the lay… #1376

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions lib/src/map/flutter_map_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class FlutterMapState extends MapGestureMixin

final MapController _localController = MapControllerImpl();

bool _hasFitInitialBounds = false;

@override
MapOptions get options => widget.options;

Expand All @@ -40,13 +42,7 @@ class FlutterMapState extends MapGestureMixin
_pixelBounds = getPixelBounds(zoom);
_bounds = _calculateBounds();

move(options.center, zoom, source: MapEventSource.initialization);

WidgetsBinding.instance.addPostFrameCallback((_) {
// Finally, fit the map to restrictions
if (options.bounds != null) {
fitBounds(options.bounds!, options.boundsOptions);
}
options.onMapReady?.call();
});
}
Expand Down Expand Up @@ -160,17 +156,22 @@ class FlutterMapState extends MapGestureMixin
},
);

//Update on state change
_pixelBounds = getPixelBounds(zoom);
_bounds = _calculateBounds();
_pixelOrigin = getNewPixelOrigin(_center);

return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
//Update on layout change
setSize(constraints.maxWidth, constraints.maxHeight);

if (options.bounds != null && !_hasFitInitialBounds) {
final target = getBoundsCenterZoom(options.bounds!, options.boundsOptions);
_zoom = target.zoom;
_center = target.center;
_hasFitInitialBounds = true;
}

_pixelBounds = getPixelBounds(zoom);
_bounds = _calculateBounds();
_pixelOrigin = getNewPixelOrigin(_center);

return MapStateInheritedWidget(
mapState: this,
Expand Down