From aaaecca3be25a0bd6d2b7057307272ef0d0654f6 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Tue, 10 Nov 2026 16:27:42 +0100 Subject: [PATCH] Show the live map on the run screen Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WzxdWZ9CKZsNxtD5Jr9bYD --- .../workout_app/lib/widgets/run_map.dart | 31 +++++++++---------- .../workout_app/lib/widgets/run_map_slot.dart | 29 ++++++++++------- .../test/widgets/run_map_test.dart | 21 ++++++------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/stronglift_replacement/workout_app/lib/widgets/run_map.dart b/stronglift_replacement/workout_app/lib/widgets/run_map.dart index 582d3db..fca8095 100644 --- a/stronglift_replacement/workout_app/lib/widgets/run_map.dart +++ b/stronglift_replacement/workout_app/lib/widgets/run_map.dart @@ -4,9 +4,9 @@ /// /// * `RunMap.route(points: track.points)` -- a finished run. The camera /// fits the whole route ([fitPadding] keeps it clear of overlays). -/// * `RunMap.live(trackListenable: notifier)` -- the live screen. Pass a -/// `ValueListenable` (a `ValueNotifier`, or the -/// recorder's own, anything that holds the current track); the route +/// * `RunMap.live(pointsListenable: recorder.livePoints)` -- the live +/// screen. Pass a `ValueListenable>` (the recorder's +/// accepted points, oldest first); the route /// redraws on every change and, in follow mode (the default), the camera /// keeps the last point centred. Dragging the map ends follow mode; the /// recentre button (icon only) turns it back on. The listenable must stay @@ -48,11 +48,11 @@ class RunMap extends StatefulWidget { super.key, this.fitPadding = const EdgeInsets.all(40), this.tileProviderOpener = openOsmTileProvider, - }) : trackListenable = null; + }) : pointsListenable = null; - /// A live run: follows the last point of the track in [trackListenable]. + /// A live run: follows the last point in [pointsListenable]. const RunMap.live({ - required ValueListenable this.trackListenable, + required ValueListenable> this.pointsListenable, super.key, this.tileProviderOpener = openOsmTileProvider, }) : points = null, @@ -61,8 +61,8 @@ class RunMap extends StatefulWidget { /// The route in detail mode; null in live mode. final List? points; - /// The current track in live mode; null in detail mode. - final ValueListenable? trackListenable; + /// The accepted points in live mode; null in detail mode. + final ValueListenable>? pointsListenable; /// Space kept free around the fitted route (detail mode). final EdgeInsets fitPadding; @@ -81,16 +81,16 @@ class _RunMapState extends State { bool _follow = true; bool _warned = false; - bool get _live => widget.trackListenable != null; + bool get _live => widget.pointsListenable != null; List get _points => _live - ? widget.trackListenable!.value?.points ?? const [] + ? widget.pointsListenable!.value : widget.points!; @override void initState() { super.initState(); - widget.trackListenable?.addListener(_followLast); + widget.pointsListenable?.addListener(_followLast); unawaited( widget.tileProviderOpener().then((p) { if (mounted) setState(() => _tiles = p); @@ -100,7 +100,7 @@ class _RunMapState extends State { @override void dispose() { - widget.trackListenable?.removeListener(_followLast); + widget.pointsListenable?.removeListener(_followLast); _controller.dispose(); super.dispose(); } @@ -173,15 +173,14 @@ class _RunMapState extends State { @override Widget build(BuildContext context) { - final listenable = widget.trackListenable; + final listenable = widget.pointsListenable; if (listenable == null) return _map(context, widget.points!); return Stack( fit: StackFit.expand, children: [ - ValueListenableBuilder( + ValueListenableBuilder>( valueListenable: listenable, - builder: (context, track, _) => - _map(context, track?.points ?? const []), + builder: (context, points, _) => _map(context, points), ), if (!_follow) Positioned( diff --git a/stronglift_replacement/workout_app/lib/widgets/run_map_slot.dart b/stronglift_replacement/workout_app/lib/widgets/run_map_slot.dart index 112d645..4f5927c 100644 --- a/stronglift_replacement/workout_app/lib/widgets/run_map_slot.dart +++ b/stronglift_replacement/workout_app/lib/widgets/run_map_slot.dart @@ -4,20 +4,28 @@ library; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:workout_app/models/run_track.dart'; +import 'package:workout_app/services/map_tile_cache.dart'; import 'package:workout_app/ui/theme.dart'; +import 'package:workout_app/widgets/run_map.dart'; -/// Placeholder for the live map: replace the body of [build] with the map -/// widget, keeping the [ValueListenable] as its source of points. +/// The live map on the run screen: [RunMap.live] over the recorder's points, +/// clipped to the card shape. /// -/// `RunScreen` fills this space from `mapBuilder`, defaulting to this widget, -/// so a map can also be dropped in by passing a builder with no edit here. +/// `RunScreen` fills this space from `mapBuilder`, defaulting to this widget. class RunMapSlot extends StatelessWidget { /// Creates the slot; [points] updates with every accepted GPS fix. - const RunMapSlot({required this.points, super.key}); + const RunMapSlot({ + required this.points, + super.key, + this.tileProviderOpener = openOsmTileProvider, + }); /// The accepted points of the run so far, oldest first. final ValueListenable> points; + /// Where the map's tiles come from; tests pass a fake. + final TileProviderOpener tileProviderOpener; + @override Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; @@ -27,13 +35,10 @@ class RunMapSlot extends StatelessWidget { color: scheme.surfaceContainerHigh, borderRadius: BorderRadius.circular(AppRadius.md), ), - child: Center( - child: Icon( - Icons.map_outlined, - size: 48, - color: scheme.onSurfaceVariant, - semanticLabel: 'Map', - ), + clipBehavior: Clip.antiAlias, + child: RunMap.live( + pointsListenable: points, + tileProviderOpener: tileProviderOpener, ), ); } diff --git a/stronglift_replacement/workout_app/test/widgets/run_map_test.dart b/stronglift_replacement/workout_app/test/widgets/run_map_test.dart index 28b0b61..dc1e0bf 100644 --- a/stronglift_replacement/workout_app/test/widgets/run_map_test.dart +++ b/stronglift_replacement/workout_app/test/widgets/run_map_test.dart @@ -5,7 +5,6 @@ import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:latlong2/latlong.dart'; import 'package:workout_app/models/run_track.dart'; -import 'package:workout_app/services/map_tile_cache.dart'; import 'package:workout_app/widgets/run_map.dart'; import '_run_map_fixtures.dart'; @@ -161,17 +160,17 @@ void main() { testWidgets('follows the last point and draws as the track grows', ( tester, ) async { - final track = ValueNotifier(null); + final track = ValueNotifier>(const []); addTearDown(track.dispose); await _pump( tester, - RunMap.live(trackListenable: track, tileProviderOpener: fakeTiles()), + RunMap.live(pointsListenable: track, tileProviderOpener: fakeTiles()), ); expect(find.byType(PolylineLayer), findsNothing); expect(find.byType(MarkerLayer), findsNothing); final full = buildTrack(count: 4); - track.value = full; + track.value = full.points; await tester.pump(); expect(find.byType(PolylineLayer), findsOneWidget); expect( @@ -189,11 +188,11 @@ void main() { tester, ) async { final full = buildTrack(count: 4); - final track = ValueNotifier(full); + final track = ValueNotifier>(full.points); addTearDown(track.dispose); await _pump( tester, - RunMap.live(trackListenable: track, tileProviderOpener: fakeTiles()), + RunMap.live(pointsListenable: track, tileProviderOpener: fakeTiles()), ); await tester.drag(find.byType(FlutterMap), const Offset(120, 0)); await tester.pump(); @@ -202,26 +201,26 @@ void main() { expect(dragged, isNot(closeTo(full.points.last.longitude, 1e-6))); // New fixes no longer pull the camera while follow is off. - track.value = buildTrack(count: 6); + track.value = buildTrack(count: 6).points; await tester.pump(); expect(_camera(tester).center.longitude, closeTo(dragged, 1e-9)); await tester.tap(find.byIcon(Icons.my_location)); await tester.pump(); expect(find.byIcon(Icons.my_location), findsNothing); - final last = track.value!.points.last; + final last = track.value.last; expect(_camera(tester).center.longitude, closeTo(last.longitude, 1e-6)); }); testWidgets('stops listening when disposed', (tester) async { - final track = ValueNotifier(buildTrack()); + final track = ValueNotifier>(buildTrack().points); addTearDown(track.dispose); await _pump( tester, - RunMap.live(trackListenable: track, tileProviderOpener: fakeTiles()), + RunMap.live(pointsListenable: track, tileProviderOpener: fakeTiles()), ); await tester.pumpWidget(const SizedBox()); - track.value = buildTrack(count: 7); + track.value = buildTrack(count: 7).points; await tester.pump(); expect(tester.takeException(), isNull); });