FB-01: fix ambient GPS's first fix not correcting the initial zoom-2
Emulator verification caught a real bug the widget tests missed: the shell background map builds before any location fix has resolved, so ambientPosition starts null and the initial camera locks at zoom 2. The first fix to arrive only re-centered (preserving that stale zoom forever) instead of also jumping to ambientZoom.
This commit is contained in:
@@ -153,10 +153,19 @@ class _RideMapState extends State<RideMap> with WidgetsBindingObserver {
|
||||
} else if (widget.ambientPosition != null &&
|
||||
widget.ambientPosition != old.ambientPosition) {
|
||||
// FB-01: no recorded path yet -- chase the ambient GPS fix instead, the same way
|
||||
// a recording is chased above.
|
||||
// a recording is chased above. The *first* fix has to also correct the zoom, not
|
||||
// just the center: the very first build (before any fix has arrived) has no
|
||||
// ambient position yet either, so `bounds == null` locks the initial camera at
|
||||
// zoom 2 -- without this, every later fix would re-center at that same
|
||||
// never-corrected zoom 2 forever, since a plain re-center only ever preserves
|
||||
// whatever zoom the map is already at.
|
||||
final isFirstFix = old.ambientPosition == null;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || !_following) return;
|
||||
_controller.move(widget.ambientPosition!, _controller.camera.zoom);
|
||||
_controller.move(
|
||||
widget.ambientPosition!,
|
||||
isFirstFix ? ambientZoom : _controller.camera.zoom,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user