Skip to content

Commit b26fb40

Browse files
authored
fix: assert MapCamera.zoom is finite on construction (#2141)
Throw if `MapCamera` is constructed with a non-finite `zoom` Change `MapCamera.initialCamera` to be a redirecting constructor
1 parent ebc5622 commit b26fb40

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/src/map/camera/camera.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,26 @@ class MapCamera {
143143
}) : _cameraSize = size,
144144
_pixelBounds = pixelBounds,
145145
_bounds = bounds,
146-
_pixelOrigin = pixelOrigin;
146+
_pixelOrigin = pixelOrigin,
147+
assert(
148+
zoom.isFinite,
149+
'Camera `zoom` must be finite (and usually positive).\n'
150+
'(This may occur if the map tried to fit to a zero-area bounds, such '
151+
'as a bounds defined by only a single point.)',
152+
);
147153

148154
/// Initializes [MapCamera] from the given [options] and with the
149155
/// [nonRotatedSize] set to [kImpossibleSize].
150156
MapCamera.initialCamera(MapOptions options)
151-
: crs = options.crs,
152-
minZoom = options.minZoom,
153-
maxZoom = options.maxZoom,
154-
center = options.initialCenter,
155-
zoom = options.initialZoom,
156-
rotation = options.initialRotation,
157-
nonRotatedSize = kImpossibleSize;
157+
: this(
158+
crs: options.crs,
159+
minZoom: options.minZoom,
160+
maxZoom: options.maxZoom,
161+
center: options.initialCenter,
162+
zoom: options.initialZoom,
163+
rotation: options.initialRotation,
164+
nonRotatedSize: kImpossibleSize,
165+
);
158166

159167
/// Returns a new instance of [MapCamera] with the given [nonRotatedSize].
160168
MapCamera withNonRotatedSize(Size nonRotatedSize) {

0 commit comments

Comments
 (0)