Make the map path trace builder explicit and keep its state

The builder panel now labels its actions, lets the user pick round trip
or as-entered with an explanation, and only sends when "Run path trace"
is pressed. Hops, mode and the last result are kept in UiViewStateService
for the session, so going back no longer clears them and the last result
can be reopened without sending again.
This commit is contained in:
zjs81 committed 2026-10-24 21:02:19 -07:00
1 parent c131f56dae
commit 1e786b24ba
27 files changed
+832 -117

No files matched your search

+9 -1
View File
@@ -103,10 +103,18 @@ Shows node count and pin count. Tappable to expand a legend of all marker types.
## Path Trace Map
### How to Access
- From the main map's radar icon
- From the main map's menu → **Path Trace** (build your own route, see below)
- From a contact's long-press menu → "Path Trace / Ping"
- From a message's path view → radar icon
### Building a Custom Trace on the Map
1. Open the map menu and choose **Path Trace**. A panel appears at the top of the map.
2. Tap nodes on the map in the order the trace should travel. **Remove Last** and **Clear** edit the list.
3. Choose **Round trip** (the trace comes back along the same hops) or **As entered** (the hops are used exactly as listed, so add the return hops yourself).
4. Tap **Run path trace**. Nothing is sent until you press this button.
Returning from the result keeps your hops, mode and the last result (**View last result** reopens it without sending again). **Close** or the back button hides the panel without discarding the hops; reopening **Path Trace** during the same session resumes where you left off. The hops are dropped when you connect to a different radio.
### What the User Sees
A map with a polyline showing the route from your node through repeater hops to the target:
- **Green circles**: Hops with known GPS coordinates
+6
View File
@@ -1234,6 +1234,12 @@
"map_runTraceWithReturnPath": "Return back on the same path.",
"map_removeLast": "Remove Last",
"map_pathTraceCancelled": "Path trace cancelled.",
"map_pathTraceAddMoreHint": "Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.",
"map_pathTraceModeRoundTrip": "Round trip",
"map_pathTraceModeRoundTripHint": "The trace goes out through these hops and comes back the same way.",
"map_pathTraceModeAsEntered": "As entered",
"map_pathTraceModeAsEnteredHint": "The trace follows these hops exactly. Add the hops back to you yourself.",
"map_pathTraceViewLast": "View last result",
"mapCache_title": "Offline Map Cache",
"mapCache_selectAreaFirst": "Select an area to cache first",
"mapCache_noTilesToDownload": "No tiles to download for this area",
+36
View File
@@ -4246,6 +4246,42 @@ abstract class AppLocalizations {
/// **'Path trace cancelled.'**
String get map_pathTraceCancelled;
/// No description provided for @map_pathTraceAddMoreHint.
///
/// In en, this message translates to:
/// **'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'**
String get map_pathTraceAddMoreHint;
/// No description provided for @map_pathTraceModeRoundTrip.
///
/// In en, this message translates to:
/// **'Round trip'**
String get map_pathTraceModeRoundTrip;
/// No description provided for @map_pathTraceModeRoundTripHint.
///
/// In en, this message translates to:
/// **'The trace goes out through these hops and comes back the same way.'**
String get map_pathTraceModeRoundTripHint;
/// No description provided for @map_pathTraceModeAsEntered.
///
/// In en, this message translates to:
/// **'As entered'**
String get map_pathTraceModeAsEntered;
/// No description provided for @map_pathTraceModeAsEnteredHint.
///
/// In en, this message translates to:
/// **'The trace follows these hops exactly. Add the hops back to you yourself.'**
String get map_pathTraceModeAsEnteredHint;
/// No description provided for @map_pathTraceViewLast.
///
/// In en, this message translates to:
/// **'View last result'**
String get map_pathTraceViewLast;
/// No description provided for @mapCache_title.
///
/// In en, this message translates to:
+21
View File
@@ -2382,6 +2382,27 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Отменен е следването на пътя.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Кеш на офлайн карти';
+21
View File
@@ -2380,6 +2380,27 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Pfadverfolgung abgebrochen.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Offline-Karten-Cache';
+21
View File
@@ -2344,6 +2344,27 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Path trace cancelled.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Offline Map Cache';
+21
View File
@@ -2374,6 +2374,27 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Traza de ruta cancelada.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Caché de mapa sin conexión';
+21
View File
@@ -2382,6 +2382,27 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Traçage de chemin annulé';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Cache de carte hors ligne';
+21
View File
@@ -2371,6 +2371,27 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Útvonal nyomkövetés törölve.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Offline térképgyorsítótár';
+21
View File
@@ -2380,6 +2380,27 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Tracciamento del percorso annullato.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Cache mappa offline';
+21
View File
@@ -2276,6 +2276,27 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get map_pathTraceCancelled => '経路トレースはキャンセルされました';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'オフライン用地図キャッシュ';
+21
View File
@@ -2282,6 +2282,27 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get map_pathTraceCancelled => '경로 추적 기능이 취소되었습니다.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => '오프라인 지도 캐시';
+21
View File
@@ -2363,6 +2363,27 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Pad traceren geannuleerd';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Offline Kaarten Cache';
+21
View File
@@ -2399,6 +2399,27 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Śledzenie ścieżki anulowano.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Pamięć podręczna map offline';
+21
View File
@@ -2378,6 +2378,27 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Rastreamento de caminho cancelado.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Cache de Mapa Offline';
+21
View File
@@ -2384,6 +2384,27 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Отмена трассировки пути';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Кэш офлайн-карты';
+21
View File
@@ -2371,6 +2371,27 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Zrušenie stopáže cesty bolo zrušené.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Offline Mapa Pamäť';
+21
View File
@@ -2364,6 +2364,27 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Spremljanje poti je prekinjeno.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title =>
'Omrezni predpomnilnik zemljeških zemljejevskih slik';
+21
View File
@@ -2353,6 +2353,27 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Ruttspårningen avbröts.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Offline Kartcache';
+21
View File
@@ -2374,6 +2374,27 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get map_pathTraceCancelled => 'Трасування шляху скасовано.';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => 'Офлайн-кеш карти';
+21
View File
@@ -2247,6 +2247,27 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get map_pathTraceCancelled => '路径追踪已取消';
@override
String get map_pathTraceAddMoreHint =>
'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.';
@override
String get map_pathTraceModeRoundTrip => 'Round trip';
@override
String get map_pathTraceModeRoundTripHint =>
'The trace goes out through these hops and comes back the same way.';
@override
String get map_pathTraceModeAsEntered => 'As entered';
@override
String get map_pathTraceModeAsEnteredHint =>
'The trace follows these hops exactly. Add the hops back to you yourself.';
@override
String get map_pathTraceViewLast => 'View last result';
@override
String get mapCache_title => '离线地图缓存';
+31
View File
@@ -0,0 +1,31 @@
import 'package:flutter/foundation.dart';
import 'package:latlong2/latlong.dart';
import 'contact.dart';
/// The map's path-trace builder state: the hops picked so far, the trace
/// mode and the last result. Held by [UiViewStateService] for the app session
/// so leaving the map or opening the result doesn't discard it.
class MapPathTraceDraft {
bool active = false;
Uint8List? radioKey;
final List<int> pathBytes = [];
final List<int> hopWidths = [];
final List<Contact> contacts = [];
final List<LatLng> points = [];
bool returnPath = true;
Uint8List? lastResultFrame;
bool get hasHops => pathBytes.isNotEmpty;
bool belongsTo(Uint8List? selfKey) =>
radioKey == null || selfKey == null || listEquals(radioKey, selfKey);
void clear() {
pathBytes.clear();
hopWidths.clear();
contacts.clear();
points.clear();
lastResultFrame = null;
}
}
+197 -115
View File
@@ -16,6 +16,7 @@ import '../connector/meshcore_protocol.dart';
import '../l10n/l10n.dart';
import '../models/app_settings.dart';
import '../models/channel.dart';
import '../models/map_path_trace_draft.dart';
import '../models/contact.dart';
import '../models/path_history.dart';
import '../l10n/contact_localization.dart';
@@ -86,14 +87,18 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
final NetworkMapOnlineController _online = NetworkMapOnlineController();
final Set<String> _hiddenMarkerIds = {};
Set<String> _removedMarkerIds = {};
bool _isBuildingPathTrace = false;
late final MapPathTraceDraft _traceDraft = context
.read<UiViewStateService>()
.mapPathTrace;
bool get _isBuildingPathTrace => _traceDraft.active;
set _isBuildingPathTrace(bool value) => _traceDraft.active = value;
bool _isSelectingPoi = false;
bool _hasInitializedMap = false;
bool _removedMarkersLoaded = false;
final List<int> _pathTrace = [];
final List<int> _pathTraceHopWidths = [];
final List<Contact> _pathTraceContacts = [];
final List<LatLng> _points = [];
List<int> get _pathTrace => _traceDraft.pathBytes;
List<int> get _pathTraceHopWidths => _traceDraft.hopWidths;
List<Contact> get _pathTraceContacts => _traceDraft.contacts;
List<LatLng> get _points => _traceDraft.points;
final List<Polyline> _polylines = [];
bool _statsExpanded = false;
bool _showNodeLabels = true;
@@ -719,7 +724,10 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
.length;
return PopScope(
canPop: allowBack,
canPop: allowBack && !_isBuildingPathTrace,
onPopInvokedWithResult: (didPop, _) {
if (!didPop && _isBuildingPathTrace) _closePathTrace();
},
child: Scaffold(
appBar: AppBar(
backgroundColor: scheme.surface,
@@ -745,7 +753,8 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
Text(context.l10n.contacts_pathTrace),
],
),
onTap: () => _startPath(
onTap: () => _openPathTrace(
connector,
LatLng(
connector.selfLatitude!,
connector.selfLongitude!,
@@ -3700,18 +3709,40 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
),
); // Add contact to path trace contacts
_points.add(position ?? LatLng(contact.latitude!, contact.longitude!));
_traceDraft.lastResultFrame = null;
});
}
void _startPath(LatLng position) {
/// Opens the path-trace builder, resuming hops picked earlier this session
/// on the same radio.
void _openPathTrace(MeshCoreConnector connector, LatLng position) {
setState(() {
final selfKey = connector.selfPublicKey;
if (!_traceDraft.belongsTo(selfKey) || !_traceDraft.hasHops) {
_traceDraft.clear();
}
_traceDraft.radioKey = selfKey;
if (_points.isEmpty) {
_points.add(position);
} else {
_points[0] = position;
}
_isBuildingPathTrace = true;
_pathTrace.clear();
_pathTraceHopWidths.clear();
_pathTraceContacts.clear();
_points.clear();
_polylines.clear();
_points.add(position);
});
}
/// Hides the builder but keeps the picked hops and last result.
void _closePathTrace() {
setState(() {
_isBuildingPathTrace = false;
});
}
void _clearPath() {
setState(() {
final start = _points.isNotEmpty ? _points.first : null;
_traceDraft.clear();
if (start != null) _points.add(start);
});
}
@@ -3730,16 +3761,55 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
_pathTrace.length - hopByteCount,
_pathTrace.length,
);
_points.removeLast(); // Remove last point from points list
_polylines.clear(); // Clear polylines
_points.removeLast();
_traceDraft.lastResultFrame = null;
});
}
void _setTraceReturnPath(bool returnPath) {
if (_traceDraft.returnPath == returnPath) return;
setState(() {
_traceDraft.returnPath = returnPath;
_traceDraft.lastResultFrame = null;
});
}
void _openTraceResult({required bool reuseLastResult}) {
final draft = _traceDraft;
final path = Uint8List.fromList(_pathTrace);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PathTraceMapScreen(
title: context.l10n.contacts_pathTrace,
path: path,
flipPathAround: draft.returnPath,
pathHashByteWidth: context
.read<MeshCoreConnector>()
.pathHashByteWidth,
pathContacts: List.of(_pathTraceContacts),
initialTraceFrame: reuseLastResult ? draft.lastResultFrame : null,
onTraceFrame: (frame) {
// Ignore a reply for a selection the user has since changed.
if (!listEquals(draft.pathBytes, path)) return;
draft.lastResultFrame = frame;
if (mounted) setState(() {});
},
),
),
);
}
Widget _buildPathTraceOverlay() {
final l10n = context.l10n;
final theme = Theme.of(context);
final isImperial =
context.read<AppSettingsService>().settings.unitSystem ==
UnitSystem.imperial;
final hasHops = _pathTrace.isNotEmpty;
final returnPath = _traceDraft.returnPath;
const buttonSize = Size(48, 48);
final hopNames = _pathTraceContacts.map((c) => c.name).join(' → ');
return Positioned(
top: 16,
left: 16,
@@ -3763,124 +3833,136 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Expanded(
child: Text(
l10n.contacts_pathTrace,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: _overlayPrimaryTextColor,
),
),
),
TextButton.icon(
onPressed: _closePathTrace,
style: TextButton.styleFrom(minimumSize: buttonSize),
icon: const Icon(Icons.close),
label: Text(l10n.common_close),
),
],
),
const SizedBox(height: 4),
Text(
l10n.contacts_pathTrace,
hasHops ? l10n.map_pathTraceAddMoreHint : l10n.map_tapToAdd,
style: TextStyle(
fontWeight: FontWeight.bold,
color: _overlayPrimaryTextColor,
fontSize: 15,
color: _overlaySecondaryTextColor,
),
),
if (_pathTrace.isEmpty) const SizedBox(height: 8),
if (_pathTrace.isEmpty)
if (hasHops) ...[
const SizedBox(height: 8),
Text(
l10n.map_tapToAdd,
hopNames,
style: TextStyle(
fontSize: 12,
color: _overlaySecondaryTextColor,
fontSize: 16,
fontWeight: FontWeight.w600,
color: _overlayPrimaryTextColor,
),
),
SelectableText(
PathHelper.splitPathBytes(
_pathTrace,
context.read<MeshCoreConnector>().pathHashByteWidth,
).map(PathHelper.formatHopHex).join(','),
style: MeshTheme.mono(
fontSize: 18,
fontWeight: FontWeight.w700,
color: MapPalette.selected,
),
),
const SizedBox(height: 6),
if (_pathTrace.isNotEmpty)
Text(
"${l10n.path_currentPathLabel} ${formatDistance(getPathDistanceMeters(_points), isImperial: isImperial)}",
style: MeshTheme.mono(
fontSize: 12,
fontSize: 14,
color: _overlaySecondaryTextColor,
),
),
SelectableText(
PathHelper.splitPathBytes(
_pathTrace,
context.read<MeshCoreConnector>().pathHashByteWidth,
).map(PathHelper.formatHopHex).join(','),
style: MeshTheme.mono(
fontSize: 18,
fontWeight: FontWeight.w700,
color: MapPalette.selected,
),
),
// const SizedBox(height: 6),
Wrap(
alignment: WrapAlignment.center,
spacing: 1,
runSpacing: 1,
children: [
if (_pathTrace.isNotEmpty)
IconButton(
onPressed: () {
final hashW = context
.read<MeshCoreConnector>()
.pathHashByteWidth;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PathTraceMapScreen(
title: l10n.contacts_pathTrace,
path: Uint8List.fromList(_pathTrace),
flipPathAround: false,
pathHashByteWidth: hashW,
pathContacts: _pathTraceContacts,
),
),
);
setState(() {
_isBuildingPathTrace = false;
});
},
tooltip: l10n.map_runTrace,
icon: const Icon(Icons.arrow_forward_outlined),
),
if (_pathTrace.isNotEmpty)
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PathTraceMapScreen(
title: l10n.contacts_pathTrace,
path: Uint8List.fromList(_pathTrace),
flipPathAround: true,
pathHashByteWidth: context
.read<MeshCoreConnector>()
.pathHashByteWidth,
pathContacts: _pathTraceContacts,
),
),
);
setState(() {
_isBuildingPathTrace = false;
});
},
tooltip: l10n.map_runTraceWithReturnPath,
icon: const Icon(Icons.replay),
),
if (_pathTrace.isNotEmpty)
IconButton(
const SizedBox(height: 4),
Wrap(
spacing: 8,
children: [
TextButton.icon(
onPressed: _removePath,
tooltip: l10n.map_removeLast,
style: TextButton.styleFrom(minimumSize: buttonSize),
icon: const Icon(Icons.undo),
label: Text(l10n.map_removeLast),
),
if (_pathTrace.isEmpty)
IconButton(
onPressed: () {
setState(() {
_isBuildingPathTrace = false;
_pathTrace.clear();
_pathTraceHopWidths.clear();
_points.clear();
_polylines.clear();
});
showDismissibleSnackBar(
context,
content: Text(l10n.map_pathTraceCancelled),
);
},
tooltip: l10n.common_cancel,
icon: const Icon(Icons.close),
TextButton.icon(
onPressed: _clearPath,
style: TextButton.styleFrom(minimumSize: buttonSize),
icon: const Icon(Icons.delete_outline),
label: Text(l10n.common_clear),
),
],
),
],
),
const SizedBox(height: 4),
SegmentedButton<bool>(
segments: [
ButtonSegment(
value: true,
icon: const Icon(Icons.sync_alt),
label: Text(l10n.map_pathTraceModeRoundTrip),
),
ButtonSegment(
value: false,
icon: const Icon(Icons.arrow_forward),
label: Text(l10n.map_pathTraceModeAsEntered),
),
],
selected: {returnPath},
onSelectionChanged: (selection) =>
_setTraceReturnPath(selection.first),
style: SegmentedButton.styleFrom(minimumSize: buttonSize),
),
const SizedBox(height: 6),
Text(
returnPath
? l10n.map_pathTraceModeRoundTripHint
: l10n.map_pathTraceModeAsEnteredHint,
style: TextStyle(
fontSize: 14,
color: _overlaySecondaryTextColor,
),
),
const SizedBox(height: 10),
Wrap(
spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.end,
children: [
if (_traceDraft.lastResultFrame != null)
OutlinedButton.icon(
onPressed: () =>
_openTraceResult(reuseLastResult: true),
style: OutlinedButton.styleFrom(
minimumSize: buttonSize,
),
icon: const Icon(Icons.history),
label: Text(l10n.map_pathTraceViewLast),
),
FilledButton.icon(
onPressed: () =>
_openTraceResult(reuseLastResult: false),
style: FilledButton.styleFrom(minimumSize: buttonSize),
icon: const Icon(Icons.radar),
label: Text(l10n.map_runTrace),
),
],
),
],
],
),
),
+24 -1
View File
@@ -65,6 +65,13 @@ class PathTraceMapScreen extends StatefulWidget {
final int pathHashByteWidth;
final List<Contact>? pathContacts;
/// A previous PUSH_CODE_TRACE_DATA frame to show instead of sending a new
/// trace when the screen opens.
final Uint8List? initialTraceFrame;
/// Called with each trace response frame this screen receives.
final ValueChanged<Uint8List>? onTraceFrame;
const PathTraceMapScreen({
super.key,
required this.title,
@@ -75,6 +82,8 @@ class PathTraceMapScreen extends StatefulWidget {
this.targetContact,
this.pathHashByteWidth = pathHashSize,
this.pathContacts,
this.initialTraceFrame,
this.onTraceFrame,
});
@override
@@ -220,7 +229,20 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
_pathHistory = context.read<PathHistoryService>();
_pathHistory!.addListener(_onPathHistoryChanged);
_setupFrameListener();
_doPathTrace();
final initialFrame = widget.initialTraceFrame;
if (initialFrame == null) {
_doPathTrace();
return;
}
final (livePath, hopWidth) = _resolveLivePath(
context.read<MeshCoreConnector>(),
);
_tracedPath = livePath;
_tracedPathHashWidth = hopWidth;
_isLoading = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _handleTraceResponse(initialFrame);
});
}
@override
@@ -501,6 +523,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
(listEquals(frame.sublist(4, 8), _sentTagBytes) ||
listEquals(frame.sublist(4, 8), _sentAckTag))) {
_timeoutTimer?.cancel();
widget.onTraceFrame?.call(frame);
if (!mounted) return;
_handleTraceResponse(frame);
}
+3
View File
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import '../models/map_path_trace_draft.dart';
import '../storage/prefs_manager.dart';
import '../utils/contact_search.dart';
@@ -33,6 +34,8 @@ class UiViewStateService extends ChangeNotifier {
ChannelSortOption _channelsSortOption = ChannelSortOption.manual;
MapSourceOption _mapSource = MapSourceOption.local;
final MapPathTraceDraft mapPathTrace = MapPathTraceDraft();
String get contactsSelectedGroupName => _contactsSelectedGroupName;
String get contactsSearchText => _contactsSearchText;
bool get contactsSearchExpanded => _contactsSearchExpanded;
@@ -0,0 +1,46 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:latlong2/latlong.dart';
import 'package:meshcore_open/models/map_path_trace_draft.dart';
import 'package:meshcore_open/services/ui_view_state_service.dart';
void main() {
test('draft survives on the shared view state service', () {
final service = UiViewStateService();
final draft = service.mapPathTrace
..active = true
..returnPath = false;
draft.pathBytes.addAll([0xAB, 0xCD]);
draft.points.add(const LatLng(1, 2));
expect(identical(service.mapPathTrace, draft), isTrue);
expect(service.mapPathTrace.hasHops, isTrue);
expect(service.mapPathTrace.returnPath, isFalse);
});
test('clear drops hops and the last result but keeps the mode', () {
final draft = MapPathTraceDraft()
..returnPath = false
..lastResultFrame = Uint8List.fromList([1, 2, 3]);
draft.pathBytes.add(0xAB);
draft.hopWidths.add(1);
draft.points.add(const LatLng(1, 2));
draft.clear();
expect(draft.hasHops, isFalse);
expect(draft.hopWidths, isEmpty);
expect(draft.points, isEmpty);
expect(draft.lastResultFrame, isNull);
expect(draft.returnPath, isFalse);
});
test('belongsTo matches only the radio it was built on', () {
final draft = MapPathTraceDraft();
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
draft.radioKey = Uint8List.fromList([1, 2]);
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
expect(draft.belongsTo(Uint8List.fromList([3, 4])), isFalse);
});
}
+102
View File
@@ -1,5 +1,11 @@
{
"bg": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -14,6 +20,12 @@
],
"de": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -28,6 +40,12 @@
],
"es": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -42,6 +60,12 @@
],
"fr": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -56,6 +80,12 @@
],
"hu": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -70,6 +100,12 @@
],
"it": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -84,6 +120,12 @@
],
"ja": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -98,6 +140,12 @@
],
"ko": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -112,6 +160,12 @@
],
"nl": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -126,6 +180,12 @@
],
"pl": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -140,6 +200,12 @@
],
"pt": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -154,6 +220,12 @@
],
"ru": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -168,6 +240,12 @@
],
"sk": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -182,6 +260,12 @@
],
"sl": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -196,6 +280,12 @@
],
"sv": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -210,6 +300,12 @@
],
"uk": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",
@@ -224,6 +320,12 @@
],
"zh": [
"map_pathTraceAddMoreHint",
"map_pathTraceModeRoundTrip",
"map_pathTraceModeRoundTripHint",
"map_pathTraceModeAsEntered",
"map_pathTraceModeAsEnteredHint",
"map_pathTraceViewLast",
"notification_sharedLocation",
"notification_sharedLocationNamed",
"notification_reacted",