Skip to content

Commit

Permalink
fix for flickering with fitbounds, moving calculations inside the lay…
Browse files Browse the repository at this point in the history
…outbuilder (#1376)
  • Loading branch information
ibrierley committed Oct 14, 2022
1 parent cb84337 commit 4276a91
Showing 1 changed file with 11 additions and 10 deletions.
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

0 comments on commit 4276a91

Please sign in to comment.