FB-04: fix Route Planner map failing to render on cold navigation

routePlanProvider's AsyncLoading state collapsed with "route doesn't exist"
via .valueOrNull, so a brand-new route's screen briefly rendered "This route
no longer exists." with no FlutterMap in the tree before the DB stream's
first emission arrived. Add a hasValue guard mirroring waypointsAsync's
existing pattern, and replace the route planner's hardcoded initialZoom of
14 with FB-01's ambientZoom constant for street-level parity with the rest
of the app.
This commit is contained in:
2026-08-24 16:12:06 -05:00
parent 9cc1cc779f
commit e491c9ee65
3 changed files with 114 additions and 3 deletions

View File

@@ -30,6 +30,7 @@ import '../components/glass_panel.dart';
import '../components/ride_map.dart'
show
TileAttribution,
ambientZoom,
maxTileZoom,
tileMaxNativeZoom,
tileSubdomains,
@@ -112,12 +113,27 @@ class _RoutePlannerScreenState extends ConsumerState<RoutePlannerScreen>
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final route = ref.watch(routePlanProvider(widget.routeId)).valueOrNull;
final routeAsync = ref.watch(routePlanProvider(widget.routeId));
final waypointsAsync = ref.watch(routeWaypointsProvider(widget.routeId));
final waypoints = waypointsAsync.valueOrNull ?? const [];
final units = ref.watch(unitSystemProvider);
final repo = ref.read(routePlanRepositoryProvider);
// Mirrors waypointsAsync's own guard below: `.valueOrNull` alone can't tell "still
// loading" apart from "genuinely doesn't exist" -- both collapse to null. On a
// brand-new route (fresh navigation right after `repo.createRoutePlan`), this
// provider's DB stream hasn't delivered its first row yet, so without this guard
// the screen would render "This route no longer exists." for a route that is
// completely valid, with zero FlutterMap in the tree, until that first emission
// arrives.
if (!routeAsync.hasValue) {
return const Scaffold(
backgroundColor: Colors.transparent,
body: Center(child: CircularProgressIndicator()),
);
}
final route = routeAsync.value;
if (route == null) {
return Scaffold(
backgroundColor: Colors.transparent,
@@ -154,7 +170,7 @@ class _RoutePlannerScreenState extends ConsumerState<RoutePlannerScreen>
initialCenter: waypoints.isEmpty
? const ll.LatLng(0, 0)
: ll.LatLng(waypoints.first.latitude, waypoints.first.longitude),
initialZoom: waypoints.length <= 1 ? 14 : maxTileZoom - 3,
initialZoom: waypoints.length <= 1 ? ambientZoom : maxTileZoom - 3,
maxZoom: maxTileZoom,
onTap: (tapPosition, point) {
repo.addWaypoint(widget.routeId, point.latitude, point.longitude);