UI refresh: shared widgets, screen cleanups, and full translations
- Extract reusable widgets (chat composer/send pipeline, message bubble frame, reaction chips, path map scaffold, radio settings dialog, translation settings section, map POI clusters, nav tiles, etc.) and slim down the screens that used them - Map: hide/remove markers with restore, confirm before setting node location, POI clustering, semantics labels - Map cache: cancellable downloads and a bulk tile limit - Repeater: unsaved-changes guard, CLI search/copy/share transcript, framed-command debug preview, disconnected banner - Confirm before clearing chats and debug logs - Keep cached unread totals in sync on per-contact/channel updates - Move remaining hardcoded strings into l10n and translate the 98 new keys into all 17 non-English locales
This commit is contained in:
1 parent
9609a8231d
commit
88dcc5943f
100 files changed
+19778
-8167
No files matched your search
@@ -6,6 +6,7 @@ import '../l10n/l10n.dart';
|
||||
import '../services/app_debug_log_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/confirm_clear_dialog.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
|
||||
class AppDebugLogScreen extends StatelessWidget {
|
||||
@@ -17,6 +18,8 @@ class AppDebugLogScreen extends StatelessWidget {
|
||||
builder: (context, logService, _) {
|
||||
final entries = logService.entries.reversed.toList();
|
||||
final hasEntries = entries.isNotEmpty;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -47,8 +50,13 @@ class AppDebugLogScreen extends StatelessWidget {
|
||||
tooltip: context.l10n.debugLog_clearLog,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: hasEntries
|
||||
? () {
|
||||
logService.clear();
|
||||
? () async {
|
||||
final confirmed = await showConfirmClearDialog(
|
||||
context,
|
||||
title: context.l10n.debugLog_clearLog,
|
||||
message: context.l10n.debugLog_clearConfirm,
|
||||
);
|
||||
if (confirmed) logService.clear();
|
||||
}
|
||||
: null,
|
||||
),
|
||||
@@ -60,11 +68,11 @@ class AppDebugLogScreen extends StatelessWidget {
|
||||
? ListView.separated(
|
||||
itemCount: entries.length,
|
||||
separatorBuilder: (_, _) =>
|
||||
const Divider(height: 1, color: MeshPalette.line),
|
||||
Divider(height: 1, color: scheme.outlineVariant),
|
||||
itemBuilder: (context, index) {
|
||||
final entry = entries[index];
|
||||
return Container(
|
||||
color: MeshPalette.bg,
|
||||
color: scheme.surfaceContainerLowest,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
@@ -84,15 +92,18 @@ class AppDebugLogScreen extends StatelessWidget {
|
||||
TextSpan(
|
||||
text: '[${entry.tag}] ',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11.5,
|
||||
color: _levelColor(entry.level),
|
||||
fontSize: 13,
|
||||
color: _levelColor(
|
||||
context,
|
||||
entry.level,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: entry.message,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11.5,
|
||||
color: MeshPalette.ink2,
|
||||
fontSize: 13,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -102,8 +113,8 @@ class AppDebugLogScreen extends StatelessWidget {
|
||||
Text(
|
||||
entry.formattedTime,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5,
|
||||
color: MeshPalette.ink4,
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -118,25 +129,25 @@ class AppDebugLogScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icon(
|
||||
Icons.bug_report_outlined,
|
||||
size: 64,
|
||||
color: MeshPalette.ink3,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
context.l10n.debugLog_noEntries,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: MeshPalette.ink3,
|
||||
textAlign: TextAlign.center,
|
||||
style: textTheme.titleMedium?.copyWith(
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
context.l10n.debugLog_enableInSettings,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: MeshPalette.ink3,
|
||||
textAlign: TextAlign.center,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -148,36 +159,38 @@ class AppDebugLogScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Color _levelColor(AppDebugLogLevel level) {
|
||||
Color _levelColor(BuildContext context, AppDebugLogLevel level) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
switch (level) {
|
||||
case AppDebugLogLevel.info:
|
||||
return MeshPalette.blue;
|
||||
return scheme.primary;
|
||||
case AppDebugLogLevel.warning:
|
||||
return MeshPalette.warn;
|
||||
return isDark ? MeshPalette.warn : MeshPalette.warnDim;
|
||||
case AppDebugLogLevel.error:
|
||||
return MeshPalette.alert;
|
||||
return scheme.error;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildLevelIcon(BuildContext context, AppDebugLogLevel level) {
|
||||
switch (level) {
|
||||
case AppDebugLogLevel.info:
|
||||
return const Icon(
|
||||
return Icon(
|
||||
Icons.info_outline,
|
||||
size: 18,
|
||||
color: MeshPalette.blue,
|
||||
size: 20,
|
||||
color: _levelColor(context, level),
|
||||
);
|
||||
case AppDebugLogLevel.warning:
|
||||
return const Icon(
|
||||
return Icon(
|
||||
Icons.warning_amber_outlined,
|
||||
size: 18,
|
||||
color: MeshPalette.warn,
|
||||
size: 20,
|
||||
color: _levelColor(context, level),
|
||||
);
|
||||
case AppDebugLogLevel.error:
|
||||
return const Icon(
|
||||
return Icon(
|
||||
Icons.error_outline,
|
||||
size: 18,
|
||||
color: MeshPalette.alert,
|
||||
size: 20,
|
||||
color: _levelColor(context, level),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+359
-1612
File diff suppressed because it is too large.
Load diff
@@ -6,6 +6,7 @@ import '../services/ble_debug_log_service.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/confirm_clear_dialog.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
|
||||
enum _BleLogView { frames, rawLogRx }
|
||||
@@ -37,6 +38,9 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
final hasEntries = showingFrames
|
||||
? entries.isNotEmpty
|
||||
: rawEntries.isNotEmpty;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final rxColor = isDark ? MeshPalette.signal : MeshPalette.signalDim;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AdaptiveAppBarTitle(context.l10n.debugLog_bleTitle),
|
||||
@@ -73,8 +77,13 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
tooltip: context.l10n.debugLog_clearLog,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: hasEntries
|
||||
? () {
|
||||
logService.clear();
|
||||
? () async {
|
||||
final confirmed = await showConfirmClearDialog(
|
||||
context,
|
||||
title: context.l10n.debugLog_clearLog,
|
||||
message: context.l10n.debugLog_clearConfirm,
|
||||
);
|
||||
if (confirmed) logService.clear();
|
||||
}
|
||||
: null,
|
||||
),
|
||||
@@ -111,7 +120,7 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
? entries.length
|
||||
: rawEntries.length,
|
||||
separatorBuilder: (_, _) =>
|
||||
const Divider(height: 1, color: MeshPalette.line),
|
||||
Divider(height: 1, color: scheme.outlineVariant),
|
||||
itemBuilder: (context, index) {
|
||||
if (showingFrames) {
|
||||
final entry = entries[index];
|
||||
@@ -144,7 +153,7 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
onLongPress: copyHex,
|
||||
onSecondaryTap: copyHex,
|
||||
child: Container(
|
||||
color: MeshPalette.bg,
|
||||
color: scheme.surfaceContainerLowest,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
@@ -157,10 +166,10 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
entry.outgoing
|
||||
? Icons.upload
|
||||
: Icons.download,
|
||||
size: 18,
|
||||
size: 20,
|
||||
color: entry.outgoing
|
||||
? MeshPalette.blue
|
||||
: MeshPalette.signal,
|
||||
? scheme.primary
|
||||
: rxColor,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
@@ -171,24 +180,24 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
Text(
|
||||
entry.description,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11.5,
|
||||
color: MeshPalette.ink,
|
||||
fontSize: 13,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
entry.hexPreview,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10,
|
||||
color: MeshPalette.ink3,
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
time,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5,
|
||||
color: MeshPalette.ink4,
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -207,7 +216,7 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
return GestureDetector(
|
||||
onTap: () => _showRawDialog(context, info),
|
||||
child: Container(
|
||||
color: MeshPalette.bg,
|
||||
color: scheme.surfaceContainerLowest,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
@@ -215,10 +224,10 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(
|
||||
Icon(
|
||||
Icons.download,
|
||||
size: 18,
|
||||
color: MeshPalette.signal,
|
||||
size: 20,
|
||||
color: rxColor,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
@@ -229,24 +238,24 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
Text(
|
||||
info.title,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11.5,
|
||||
color: MeshPalette.ink,
|
||||
fontSize: 13,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
info.summary,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10,
|
||||
color: MeshPalette.ink3,
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
time,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5,
|
||||
color: MeshPalette.ink4,
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -259,9 +268,14 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
},
|
||||
)
|
||||
: Center(
|
||||
child: Text(
|
||||
context.l10n.debugLog_noBleActivity,
|
||||
style: const TextStyle(color: MeshPalette.ink3),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(
|
||||
context.l10n.debugLog_noBleActivity,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyLarge
|
||||
?.copyWith(color: scheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+1005
-899
File diff suppressed because it is too large.
Load diff
+150
-554
@@ -24,22 +24,21 @@ import '../models/channel_message.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
import '../models/message.dart';
|
||||
import '../models/translation_support.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/chat_text_scale_service.dart';
|
||||
import '../services/path_history_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../widgets/chat_composer.dart';
|
||||
import '../widgets/chat_send_pipeline.dart';
|
||||
import '../widgets/chat_zoom_wrapper.dart';
|
||||
import '../widgets/byte_count_input.dart';
|
||||
import '../widgets/marker_label_dialog.dart';
|
||||
import '../widgets/message_bubble_frame.dart';
|
||||
import '../widgets/reaction_chips.dart';
|
||||
import '../widgets/chat_day_separator.dart';
|
||||
import 'channel_message_path_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
import '../widgets/emoji_picker.dart';
|
||||
import '../widgets/gif_message.dart';
|
||||
import '../widgets/jump_to_bottom_button.dart';
|
||||
import '../widgets/gif_picker.dart';
|
||||
import '../widgets/message_translation_button.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
import '../widgets/radio_stats_entry.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
@@ -83,14 +82,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
MeshCoreConnector? _connector;
|
||||
Message? _pendingUnreadScrollTarget;
|
||||
String? _unreadDividerMessageId;
|
||||
DateTime? _lastTextSendAt;
|
||||
// True while a send is awaiting outgoing translation, so a second tap
|
||||
// can't send the same text again.
|
||||
bool _isSendingText = false;
|
||||
final ChatSendGuard _sendGuard = ChatSendGuard();
|
||||
|
||||
/// Contact keys of the chat screens currently on the navigation stack, in
|
||||
/// push order. A room chat can push a nested ChatScreen for one of its
|
||||
/// posters; when that one is popped, the room underneath must become the
|
||||
/// active conversation again rather than none at all.
|
||||
static final List<String> _activeContactStack = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_activeContactStack.add(widget.contact.publicKeyHex);
|
||||
_textFieldFocusNode.addListener(_onTextFieldFocusChange);
|
||||
_scrollController.onScrollNearTop = _loadOlderMessages;
|
||||
_scrollController.showJumpToBottom.addListener(_clearDividerAtBottom);
|
||||
@@ -179,7 +182,16 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_connector?.setActiveContact(null);
|
||||
final index = _activeContactStack.lastIndexOf(widget.contact.publicKeyHex);
|
||||
final wasTop = index == _activeContactStack.length - 1;
|
||||
if (index >= 0) _activeContactStack.removeAt(index);
|
||||
if (wasTop) {
|
||||
// Restore whichever chat is now on top (e.g. the room this nested chat
|
||||
// was opened from), or clear when this was the only one.
|
||||
_connector?.setActiveContact(
|
||||
_activeContactStack.isEmpty ? null : _activeContactStack.last,
|
||||
);
|
||||
}
|
||||
_scrollController.showJumpToBottom.removeListener(_clearDividerAtBottom);
|
||||
_textFieldFocusNode.removeListener(_onTextFieldFocusChange);
|
||||
_textFieldFocusNode.dispose();
|
||||
@@ -212,15 +224,26 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
ContactRoutingSheet.show(context, contact: contact),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Text(
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.normal,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationStyle: TextDecorationStyle.dotted,
|
||||
),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
// Follows the chat text size, capped so the two-line
|
||||
// title still fits the app bar.
|
||||
final textScale = context
|
||||
.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
)
|
||||
.clamp(1.0, 1.3);
|
||||
return Text(
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * textScale,
|
||||
fontWeight: FontWeight.normal,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationStyle: TextDecorationStyle.dotted,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -478,363 +501,77 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
Widget _buildInputBar(MeshCoreConnector connector) {
|
||||
final maxBytes = maxContactMessageBytes();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final settings = context.watch<AppSettingsService>().settings;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surface,
|
||||
border: Border(top: BorderSide(color: scheme.outlineVariant, width: 1)),
|
||||
final keyHex = widget.contact.publicKeyHex;
|
||||
final useEncoder =
|
||||
connector.isContactSmazEnabled(keyHex) ||
|
||||
connector.isContactCyr2LatEnabled(keyHex);
|
||||
return ChatComposer(
|
||||
controller: _textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
maxBytes: maxContactMessageBytes(),
|
||||
softLimitBytes: maxTextPayloadBytesAfterFullLengthAttempts,
|
||||
softLimitNote: context.l10n.chat_longMessageRetryNote(
|
||||
maxFullLengthTextAttempt + 1,
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Builder(
|
||||
builder: (menuContext) {
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline),
|
||||
tooltip: context.l10n.chat_selectSendAction,
|
||||
onPressed: () async {
|
||||
final RenderBox button =
|
||||
menuContext.findRenderObject() as RenderBox;
|
||||
final RenderBox overlay =
|
||||
Overlay.of(menuContext).context.findRenderObject()
|
||||
as RenderBox;
|
||||
final Offset buttonOffset = button.localToGlobal(
|
||||
Offset.zero,
|
||||
ancestor: overlay,
|
||||
);
|
||||
const menuHeight = 2 * kMinInteractiveDimension + 16;
|
||||
final menuTop = (buttonOffset.dy - menuHeight).clamp(
|
||||
8.0,
|
||||
overlay.size.height,
|
||||
);
|
||||
final position = RelativeRect.fromLTRB(
|
||||
buttonOffset.dx,
|
||||
menuTop,
|
||||
overlay.size.width -
|
||||
buttonOffset.dx -
|
||||
button.size.width,
|
||||
overlay.size.height - buttonOffset.dy,
|
||||
);
|
||||
|
||||
final selected = await showMenu<String>(
|
||||
context: menuContext,
|
||||
position: position,
|
||||
items: [
|
||||
PopupMenuItem(
|
||||
value: 'gif',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.gif_box),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.chat_sendGif),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'send-my-location',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.my_location),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.chat_shareMyLocation),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
if (!mounted || !menuContext.mounted) return;
|
||||
if (selected == null) return;
|
||||
switch (selected) {
|
||||
case 'gif':
|
||||
_showGifPicker(context);
|
||||
break;
|
||||
case 'send-my-location':
|
||||
await _shareMyLocation(
|
||||
context.read<MeshCoreConnector>(),
|
||||
);
|
||||
break;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
if (settings.translationEnabled)
|
||||
MessageTranslationButton(
|
||||
enabled: settings.composerTranslationEnabled,
|
||||
languageCode: settings.translationTargetLanguageCode,
|
||||
onPressed: _showTranslationOptions,
|
||||
),
|
||||
// No image button here: the image wire format is GRP_DATA, a
|
||||
// channel primitive with no DM equivalent (see the note at the
|
||||
// top of this file).
|
||||
Expanded(
|
||||
child: ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _textController,
|
||||
builder: (context, value, child) {
|
||||
final gifId = GifHelper.parseGif(value.text);
|
||||
if (gifId != null) {
|
||||
return Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
(event.logicalKey == LogicalKeyboardKey.enter ||
|
||||
event.logicalKey ==
|
||||
LogicalKeyboardKey.numpadEnter)) {
|
||||
_sendMessage(connector);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: GifMessage(
|
||||
url:
|
||||
'https://media.giphy.com/media/$gifId/giphy.gif',
|
||||
backgroundColor:
|
||||
scheme.surfaceContainerHighest,
|
||||
fallbackTextColor: scheme.onSurface
|
||||
.withValues(alpha: 0.6),
|
||||
maxSize: 160,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: context.l10n.chat_removeGif,
|
||||
onPressed: () {
|
||||
_textController.clear();
|
||||
_textFieldFocusNode.requestFocus();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return ByteCountedTextField(
|
||||
maxBytes: maxBytes,
|
||||
softLimitBytes:
|
||||
maxTextPayloadBytesAfterFullLengthAttempts,
|
||||
softLimitNote: context.l10n.chat_longMessageRetryNote(
|
||||
maxFullLengthTextAttempt + 1,
|
||||
),
|
||||
controller: _textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
hintText: context.l10n.chat_typeMessage,
|
||||
onSubmitted: (_) => _sendMessage(connector),
|
||||
encoder:
|
||||
(connector.isContactSmazEnabled(
|
||||
widget.contact.publicKeyHex,
|
||||
) ||
|
||||
connector.isContactCyr2LatEnabled(
|
||||
widget.contact.publicKeyHex,
|
||||
))
|
||||
? (text) => connector.prepareContactOutboundText(
|
||||
widget.contact,
|
||||
text,
|
||||
)
|
||||
: null,
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.chat_typeMessage,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
borderSide: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
borderSide: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
borderSide: BorderSide(
|
||||
color: scheme.primary,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: scheme.surfaceContainerLow,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _textController,
|
||||
builder: (context, value, _) {
|
||||
final hasText = value.text.trim().isNotEmpty;
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton.filled(
|
||||
icon: const Icon(Icons.send, size: 20),
|
||||
tooltip: context.l10n.chat_sendMessageTo(
|
||||
_resolveContact(connector).name,
|
||||
),
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: hasText
|
||||
? scheme.primary
|
||||
: scheme.surfaceContainerHighest,
|
||||
foregroundColor: hasText
|
||||
? scheme.onPrimary
|
||||
: scheme.onSurfaceVariant,
|
||||
minimumSize: const Size(40, 40),
|
||||
shape: const CircleBorder(),
|
||||
),
|
||||
onPressed: hasText
|
||||
? () {
|
||||
HapticFeedback.lightImpact();
|
||||
_sendMessage(connector);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
encoder: useEncoder
|
||||
? (text) => connector.prepareContactOutboundText(widget.contact, text)
|
||||
: null,
|
||||
onSend: () => _sendMessage(connector),
|
||||
sendTooltip: context.l10n.chat_sendMessageTo(
|
||||
_resolveContact(connector).name,
|
||||
),
|
||||
// No image action here: the image wire format is GRP_DATA, a channel
|
||||
// primitive with no DM equivalent (see the note at the top of this
|
||||
// file).
|
||||
actionsBuilder: () => [
|
||||
ChatComposerAction(
|
||||
id: 'gif',
|
||||
icon: Icons.gif_box,
|
||||
label: context.l10n.chat_sendGif,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showGifPicker(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => GifPicker(
|
||||
onGifSelected: (gifId) {
|
||||
_textController.text = GifHelper.encodeGif(gifId);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showTranslationOptions() async {
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
final settings = settingsService.settings;
|
||||
await showMessageTranslationSheet(
|
||||
context: context,
|
||||
enabled: settings.composerTranslationEnabled,
|
||||
selectedLanguageCode: settings.translationTargetLanguageCode,
|
||||
onEnabledChanged: settingsService.setComposerTranslationEnabled,
|
||||
onLanguageSelected: settingsService.setTranslationTargetLanguageCode,
|
||||
ChatComposerAction(
|
||||
id: 'send-my-location',
|
||||
icon: Icons.my_location,
|
||||
label: context.l10n.chat_shareMyLocation,
|
||||
),
|
||||
],
|
||||
onAction: (action) {
|
||||
if (!mounted) return;
|
||||
switch (action) {
|
||||
case 'gif':
|
||||
showChatGifPicker(context, _textController);
|
||||
case 'send-my-location':
|
||||
_shareMyLocation(context.read<MeshCoreConnector>());
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Shares the radio's own position as a map marker. Shares the text send
|
||||
/// guard and cooldown so it can't race or flood alongside typed messages.
|
||||
Future<void> _shareMyLocation(MeshCoreConnector connector) async {
|
||||
final lat = connector.selfLatitude;
|
||||
final lon = connector.selfLongitude;
|
||||
if (!hasShareableLocation(lat, lon)) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_noRadioLocation),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final selfName = connector.selfName;
|
||||
final label = await showMarkerLabelDialog(
|
||||
context,
|
||||
lat: lat!,
|
||||
lon: lon!,
|
||||
defaultLabel: selfName != null && selfName.isNotEmpty
|
||||
? selfName
|
||||
: context.l10n.map_sharedPin,
|
||||
flags: 'poi',
|
||||
confirmText: context.l10n.common_share,
|
||||
Future<void> _shareMyLocation(MeshCoreConnector connector) {
|
||||
return shareMyLocationMarker(
|
||||
context: context,
|
||||
connector: connector,
|
||||
guard: _sendGuard,
|
||||
send: (markerText) =>
|
||||
connector.sendMessage(_resolveContact(connector), markerText),
|
||||
);
|
||||
if (label == null || label.isEmpty || !mounted || _isSendingText) return;
|
||||
final now = DateTime.now();
|
||||
if (_lastTextSendAt != null &&
|
||||
now.difference(_lastTextSendAt!) < const Duration(seconds: 1)) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_sendCooldown),
|
||||
);
|
||||
return;
|
||||
}
|
||||
_lastTextSendAt = now;
|
||||
_isSendingText = true;
|
||||
try {
|
||||
await connector.sendMessage(
|
||||
_resolveContact(connector),
|
||||
formatMarkerText(lat, lon, label, 'poi'),
|
||||
);
|
||||
} catch (e) {
|
||||
appLogger.warn('Sharing location failed: $e', tag: 'Chat');
|
||||
} finally {
|
||||
_isSendingText = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendMessage(MeshCoreConnector connector) async {
|
||||
if (_isSendingText) return;
|
||||
_isSendingText = true;
|
||||
try {
|
||||
await _sendMessageInner(connector);
|
||||
} finally {
|
||||
_isSendingText = false;
|
||||
}
|
||||
Future<void> _sendMessage(MeshCoreConnector connector) {
|
||||
return _sendGuard.runExclusive(() => _sendMessageInner(connector));
|
||||
}
|
||||
|
||||
Future<void> _sendMessageInner(MeshCoreConnector connector) async {
|
||||
final text = _textController.text.trim();
|
||||
if (text.isEmpty) return;
|
||||
if (!_sendGuard.checkCooldown(context)) return;
|
||||
|
||||
final now = DateTime.now();
|
||||
if (_lastTextSendAt != null &&
|
||||
now.difference(_lastTextSendAt!) < const Duration(seconds: 1)) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_sendCooldown),
|
||||
);
|
||||
return;
|
||||
}
|
||||
_lastTextSendAt = now;
|
||||
final translation = await translateOutgoingText(context, text);
|
||||
if (translation == null || !mounted) return;
|
||||
var outgoingText = translation.text;
|
||||
|
||||
final settings = context.read<AppSettingsService>().settings;
|
||||
final translationService = context.read<TranslationService>();
|
||||
var outgoingText = text;
|
||||
String? originalText;
|
||||
String? translatedLanguageCode;
|
||||
String? translationModelId;
|
||||
if (settings.translationEnabled) {
|
||||
final targetLanguageCode = translationService.resolvedTargetLanguageCode(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
if (translationService.shouldTranslateOutgoing(
|
||||
text: text,
|
||||
targetLanguageCode: targetLanguageCode,
|
||||
)) {
|
||||
final result = await translationService.translateOutgoingText(
|
||||
text: text,
|
||||
targetLanguageCode: targetLanguageCode,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (result != null &&
|
||||
result.status == MessageTranslationStatus.completed &&
|
||||
result.translatedText.isNotEmpty) {
|
||||
outgoingText = result.translatedText;
|
||||
originalText = text;
|
||||
translatedLanguageCode = result.targetLanguageCode;
|
||||
translationModelId = result.modelId;
|
||||
}
|
||||
}
|
||||
}
|
||||
final maxBytes = maxContactMessageBytes();
|
||||
final outboundText = connector.prepareContactOutboundText(
|
||||
_resolveContact(connector),
|
||||
@@ -868,36 +605,23 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
connector.sendMessage(
|
||||
_resolveContact(connector),
|
||||
outgoingText,
|
||||
originalText: originalText,
|
||||
translatedLanguageCode: translatedLanguageCode,
|
||||
translationModelId: translationModelId,
|
||||
originalText: translation.originalText,
|
||||
translatedLanguageCode: translation.languageCode,
|
||||
translationModelId: translation.modelId,
|
||||
);
|
||||
// Only a dispatched send starts the cooldown.
|
||||
_sendGuard.markDispatched();
|
||||
}
|
||||
|
||||
Future<void> _confirmClearChat(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(context.l10n.contact_clearChat),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
child: Text(context.l10n.common_delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
final confirmed = await confirmClearChat(
|
||||
context,
|
||||
message: context.l10n.chat_clearChatConfirm,
|
||||
);
|
||||
if (confirmed == true) {
|
||||
if (confirmed) {
|
||||
connector.clearMessagesForContact(widget.contact);
|
||||
}
|
||||
}
|
||||
@@ -1020,7 +744,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
connector.ensureContactSmazSettingLoaded(widget.contact.publicKeyHex);
|
||||
connector.ensureContactCyr2LatSettingLoaded(widget.contact.publicKeyHex);
|
||||
final contact = widget.contact;
|
||||
// The live contact carries the current telemetry flags; widget.contact
|
||||
// is the snapshot this screen was opened with.
|
||||
final contact = _resolveContact(connector);
|
||||
bool smazEnabled = connector.isContactSmazEnabled(contact.publicKeyHex);
|
||||
bool cyr2latEnabled = connector.isContactCyr2LatEnabled(
|
||||
contact.publicKeyHex,
|
||||
@@ -1034,6 +760,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
bool teleBaseEnabled = contact.teleBaseEnabled;
|
||||
bool teleLocEnabled = contact.teleLocEnabled;
|
||||
bool teleEnvEnabled = contact.teleEnvEnabled;
|
||||
// Each toggle is committed immediately, like the compression switches,
|
||||
// so dismissing the dialog by tapping outside keeps the change. All three
|
||||
// flags are sent every time so overlapping writes can't undo each other.
|
||||
void commitTelemetryFlags() {
|
||||
connector.setContactFlags(
|
||||
contact,
|
||||
teleBase: teleBaseEnabled,
|
||||
teleLoc: teleLocEnabled,
|
||||
teleEnv: teleEnvEnabled,
|
||||
);
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => StatefulBuilder(
|
||||
@@ -1147,6 +885,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
value: teleBaseEnabled,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => teleBaseEnabled = value);
|
||||
commitTelemetryFlags();
|
||||
},
|
||||
),
|
||||
const Divider(height: 8),
|
||||
@@ -1157,6 +896,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
value: teleLocEnabled,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => teleLocEnabled = value);
|
||||
commitTelemetryFlags();
|
||||
},
|
||||
),
|
||||
const Divider(height: 8),
|
||||
@@ -1167,6 +907,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
value: teleEnvEnabled,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => teleEnvEnabled = value);
|
||||
commitTelemetryFlags();
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -1174,15 +915,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
connector.setContactFlags(
|
||||
contact,
|
||||
teleBase: teleBaseEnabled,
|
||||
teleLoc: teleLocEnabled,
|
||||
teleEnv: teleEnvEnabled,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(context.l10n.common_close),
|
||||
),
|
||||
],
|
||||
@@ -1341,7 +1074,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
title: Text(context.l10n.common_copy),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_copyMessageText(message.text);
|
||||
copyChatMessageText(context, message.text);
|
||||
},
|
||||
),
|
||||
if (canTranslateMessage)
|
||||
@@ -1409,17 +1142,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _copyMessageText(String text) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
// Android shows its own clipboard chip; the snackbar is redundant there
|
||||
// and lingers over the input field after the chip dismisses.
|
||||
if (PlatformInfo.isAndroid) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_messageCopied),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _deleteMessage(Message message) async {
|
||||
await context.read<MeshCoreConnector>().deleteMessage(message);
|
||||
if (!mounted) return;
|
||||
@@ -1503,40 +1225,15 @@ class _MessageBubble extends StatelessWidget {
|
||||
(connector) => connector.isContactUrlImagesEnabled(sourceId),
|
||||
);
|
||||
|
||||
// Bubble colors — outgoing uses MeshPalette.me / meBorder / meInk.
|
||||
final bubbleColor = isFailed
|
||||
? scheme.errorContainer
|
||||
: isOutgoing
|
||||
? MeshPalette.me
|
||||
: scheme.surfaceContainerLow;
|
||||
final bubbleBorder = isFailed
|
||||
? scheme.error
|
||||
: isOutgoing
|
||||
? MeshPalette.meBorder
|
||||
: scheme.outlineVariant;
|
||||
final textColor = isFailed
|
||||
? scheme.onErrorContainer
|
||||
: isOutgoing
|
||||
? MeshPalette.meInk
|
||||
: scheme.onSurface;
|
||||
final metaColor = textColor.withValues(alpha: 0.65);
|
||||
final colors = MessageBubbleColors.of(
|
||||
scheme,
|
||||
isOutgoing: isOutgoing,
|
||||
isFailed: isFailed,
|
||||
);
|
||||
final textColor = colors.text;
|
||||
final metaColor = colors.meta;
|
||||
const bodyFontSize = 14.0;
|
||||
|
||||
// Asymmetric radius: outgoing — top-left large, others also large; outgoing bottom-right tight.
|
||||
final borderRadius = isOutgoing
|
||||
? const BorderRadius.only(
|
||||
topLeft: Radius.circular(MeshRadii.lg),
|
||||
topRight: Radius.circular(MeshRadii.lg),
|
||||
bottomLeft: Radius.circular(MeshRadii.lg),
|
||||
bottomRight: Radius.circular(MeshRadii.xs),
|
||||
)
|
||||
: const BorderRadius.only(
|
||||
topLeft: Radius.circular(MeshRadii.xs),
|
||||
topRight: Radius.circular(MeshRadii.lg),
|
||||
bottomLeft: Radius.circular(MeshRadii.lg),
|
||||
bottomRight: Radius.circular(MeshRadii.lg),
|
||||
);
|
||||
|
||||
// Do not strip room-server author bytes here: the parser stores them in
|
||||
// fourByteRoomContactKey, so message.text is safe to render as-is.
|
||||
final messageText = message.text;
|
||||
@@ -1597,21 +1294,11 @@ class _MessageBubble extends StatelessWidget {
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: gifId != null
|
||||
? const EdgeInsets.all(4)
|
||||
: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.72,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: bubbleColor,
|
||||
borderRadius: borderRadius,
|
||||
border: Border.all(color: bubbleBorder, width: 1),
|
||||
),
|
||||
child: MessageBubbleFrame(
|
||||
isOutgoing: isOutgoing,
|
||||
isFailed: isFailed,
|
||||
compact: gifId != null,
|
||||
maxWidth: constraints.maxWidth,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -1627,9 +1314,9 @@ class _MessageBubble extends StatelessWidget {
|
||||
child: Text(
|
||||
senderName,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontSize: 13 * textScale,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _colorForName(senderName),
|
||||
color: senderNameColor(senderName),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1725,7 +1412,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
context.l10n.urlImage_possible,
|
||||
style: TextStyle(
|
||||
color: metaColor,
|
||||
fontSize: 11 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1749,7 +1436,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
.maxMessageRetries,
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
@@ -1801,7 +1488,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
const SizedBox(width: 2),
|
||||
Icon(
|
||||
Icons.speed,
|
||||
size: 10 * textScale,
|
||||
size: 14 * textScale,
|
||||
color: isOutgoing
|
||||
? metaColor
|
||||
: scheme.tertiary,
|
||||
@@ -1809,7 +1496,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
Text(
|
||||
'${(message.tripTimeMs! / 1000).toStringAsFixed(1)}s',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: isOutgoing
|
||||
? metaColor
|
||||
: scheme.tertiary,
|
||||
@@ -1831,7 +1518,13 @@ class _MessageBubble extends StatelessWidget {
|
||||
const SizedBox(height: 4),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: isOutgoing ? 0 : 42),
|
||||
child: _buildReactionsDisplay(context, message, scheme),
|
||||
child: ReactionChips(
|
||||
reactions: message.reactions,
|
||||
statuses: message.reactionStatuses,
|
||||
onRetry: onRetryReaction == null
|
||||
? null
|
||||
: (emoji) => onRetryReaction!(message, emoji),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
@@ -1905,104 +1598,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReactionsDisplay(
|
||||
BuildContext context,
|
||||
Message message,
|
||||
ColorScheme scheme,
|
||||
) {
|
||||
return Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: message.reactions.entries.map((entry) {
|
||||
final emoji = entry.key;
|
||||
final count = entry.value.length;
|
||||
final status = message.reactionStatuses[emoji];
|
||||
final isPending =
|
||||
status == MessageStatus.pending || status == MessageStatus.sent;
|
||||
final isFailed = status == MessageStatus.failed;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: isFailed && onRetryReaction != null
|
||||
? () => onRetryReaction!(message, emoji)
|
||||
: null,
|
||||
child: Opacity(
|
||||
opacity: isPending ? 0.5 : 1.0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: isFailed
|
||||
? scheme.errorContainer
|
||||
: scheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
border: Border.all(
|
||||
color: isFailed ? scheme.error : scheme.outlineVariant,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
emoji,
|
||||
style: MeshTheme.emoji(fontSize: 16),
|
||||
textHeightBehavior: const TextHeightBehavior(
|
||||
applyHeightToFirstAscent: false,
|
||||
applyHeightToLastDescent: false,
|
||||
),
|
||||
),
|
||||
if (count > 1) ...[
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'$count',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (isPending) ...[
|
||||
const SizedBox(width: 2),
|
||||
SizedBox(
|
||||
width: 8,
|
||||
height: 8,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 1.5,
|
||||
color: scheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (isFailed) ...[
|
||||
const SizedBox(width: 2),
|
||||
Icon(Icons.replay, size: 10, color: scheme.error),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAvatar(String senderName) {
|
||||
return AvatarCircle(name: senderName, size: 32);
|
||||
}
|
||||
}
|
||||
|
||||
/// Deterministic name-to-hue mapping consistent with [AvatarCircle].
|
||||
Color _colorForName(String name) {
|
||||
const hues = [
|
||||
MeshPalette.blue,
|
||||
MeshPalette.magenta,
|
||||
MeshPalette.signal,
|
||||
MeshPalette.warn,
|
||||
Color(0xFF8FA8F0),
|
||||
Color(0xFF6FD9CE),
|
||||
];
|
||||
var h = 0;
|
||||
for (final c in name.codeUnits) {
|
||||
h = (h * 31 + c) & 0x7fffffff;
|
||||
}
|
||||
return hues[h % hues.length];
|
||||
}
|
||||
@@ -32,6 +32,24 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
final CommunityStore _communityStore = CommunityStore();
|
||||
bool _isProcessing = false;
|
||||
|
||||
/// QR data whose join prompt was just cancelled. Ignored for a short
|
||||
/// cooldown so a code still in view doesn't immediately re-prompt.
|
||||
String? _cancelledData;
|
||||
DateTime? _cancelledAt;
|
||||
static const Duration _cancelCooldown = Duration(seconds: 3);
|
||||
|
||||
void _markCancelled(String data) {
|
||||
_cancelledData = data;
|
||||
_cancelledAt = DateTime.now();
|
||||
}
|
||||
|
||||
bool _isRecentlyCancelled(String data) {
|
||||
final at = _cancelledAt;
|
||||
return data == _cancelledData &&
|
||||
at != null &&
|
||||
DateTime.now().difference(at) < _cancelCooldown;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -40,87 +58,21 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
centerTitle: true,
|
||||
),
|
||||
body: _isProcessing
|
||||
? Container(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
? const QrScannerProcessingBody()
|
||||
: QrScannerWidget(
|
||||
onScanned: (data) => _handleScannedData(context, data),
|
||||
validator: Community.isValidQrData,
|
||||
onValidationFailed: (_) => _showInvalidQrError(context),
|
||||
validator: (data) =>
|
||||
Community.isValidQrData(data) && !_isRecentlyCancelled(data),
|
||||
onValidationFailed: (data) {
|
||||
if (_isRecentlyCancelled(data)) return;
|
||||
_showInvalidQrError(context);
|
||||
},
|
||||
instructions: context.l10n.community_scanInstructions,
|
||||
overlay: _buildThemedOverlay(context),
|
||||
themed: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildThemedOverlay(BuildContext context) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Dark semi-transparent background with cutout
|
||||
ColorFiltered(
|
||||
colorFilter: ColorFilter.mode(
|
||||
Colors.black.withValues(alpha: 0.5),
|
||||
BlendMode.srcOut,
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
backgroundBlendMode: BlendMode.dstOut,
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Container(
|
||||
height: 250,
|
||||
width: 250,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Corner brackets on top
|
||||
const ScannerCornerOverlay(
|
||||
scanWindowSize: 250,
|
||||
borderColor: MeshPalette.blue,
|
||||
borderWidth: 2,
|
||||
cornerLength: 24,
|
||||
),
|
||||
// Instructions pill below the scan window
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 250 + 24),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.72),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
),
|
||||
child: Text(
|
||||
context.l10n.community_scanInstructions,
|
||||
style: const TextStyle(color: MeshPalette.ink2, fontSize: 13),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleScannedData(BuildContext context, String data) async {
|
||||
if (_isProcessing) return;
|
||||
|
||||
@@ -130,6 +82,9 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
_communityStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
// Set when this screen is about to pop: keep the spinner up so the camera
|
||||
// doesn't restart on a closing route and detect the code again.
|
||||
var leaving = false;
|
||||
|
||||
try {
|
||||
// Parse the community data
|
||||
@@ -142,14 +97,15 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
|
||||
if (existing != null) {
|
||||
if (context.mounted) {
|
||||
_showAlreadyMemberDialog(context, existing);
|
||||
leaving = await _showAlreadyMemberDialog(context, existing);
|
||||
if (!leaving) _markCancelled(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Show confirmation dialog
|
||||
if (context.mounted) {
|
||||
await _showJoinConfirmationDialog(context, community);
|
||||
leaving = await _showJoinConfirmationDialog(context, community, data);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
@@ -160,7 +116,7 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
if (mounted && !leaving) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
});
|
||||
@@ -169,16 +125,15 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
}
|
||||
|
||||
void _showInvalidQrError(BuildContext context) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.community_invalidQrCode),
|
||||
backgroundColor: MeshPalette.warn,
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
showInvalidQrSnackBar(context, context.l10n.community_invalidQrCode);
|
||||
}
|
||||
|
||||
void _showAlreadyMemberDialog(BuildContext context, Community community) {
|
||||
showMeshSheet(
|
||||
/// Returns true when the screen popped itself (OK pressed).
|
||||
Future<bool> _showAlreadyMemberDialog(
|
||||
BuildContext context,
|
||||
Community community,
|
||||
) async {
|
||||
final ok = await showMeshSheet<bool>(
|
||||
context,
|
||||
builder: (sheetContext) {
|
||||
final sheetScheme = Theme.of(sheetContext).colorScheme;
|
||||
@@ -215,9 +170,11 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'ID: ${community.shortCommunityId}...',
|
||||
context.l10n.community_shortId(
|
||||
community.shortCommunityId,
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11.5,
|
||||
fontSize: 13,
|
||||
color: sheetScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
@@ -230,10 +187,7 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(sheetContext);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onPressed: () => Navigator.pop(sheetContext, true),
|
||||
child: Text(context.l10n.common_ok),
|
||||
),
|
||||
),
|
||||
@@ -241,11 +195,16 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
);
|
||||
},
|
||||
);
|
||||
if (ok != true || !context.mounted) return false;
|
||||
Navigator.pop(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> _showJoinConfirmationDialog(
|
||||
/// Returns true when the community was joined and the screen popped.
|
||||
Future<bool> _showJoinConfirmationDialog(
|
||||
BuildContext context,
|
||||
Community community,
|
||||
String data,
|
||||
) async {
|
||||
bool addPublicChannel = true;
|
||||
final completer = Completer<bool>();
|
||||
@@ -289,9 +248,11 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'ID: ${community.shortCommunityId}...',
|
||||
context.l10n.community_shortId(
|
||||
community.shortCommunityId,
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11.5,
|
||||
fontSize: 13,
|
||||
color: joinScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
@@ -353,14 +314,16 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
final result = await completer.future;
|
||||
|
||||
if (result && context.mounted) {
|
||||
await _joinCommunity(context, community, addPublicChannel);
|
||||
} else if (context.mounted) {
|
||||
// User cancelled - go back
|
||||
Navigator.pop(context);
|
||||
return _joinCommunity(context, community, addPublicChannel);
|
||||
}
|
||||
// User cancelled: stay on the scanner and resume scanning, ignoring this
|
||||
// code briefly so it doesn't re-prompt while still in view.
|
||||
_markCancelled(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> _joinCommunity(
|
||||
/// Returns true when the screen popped itself.
|
||||
Future<bool> _joinCommunity(
|
||||
BuildContext context,
|
||||
Community community,
|
||||
bool addPublicChannel,
|
||||
@@ -409,7 +372,9 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
|
||||
// Return to previous screen
|
||||
Navigator.pop(context, community);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int? _findNextAvailableChannelIndex(MeshCoreConnector connector) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/models/companion_radio_stats.dart';
|
||||
@@ -328,8 +329,11 @@ class _NoiseChartPainter extends CustomPainter {
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _NoiseChartPainter oldDelegate) {
|
||||
return oldDelegate.samples.length != samples.length ||
|
||||
oldDelegate.colorScheme != colorScheme;
|
||||
// Once the ring buffer is full its length stays constant, so compare the
|
||||
// contents (samples is a fresh copy per build).
|
||||
return !listEquals(oldDelegate.samples, samples) ||
|
||||
oldDelegate.colorScheme != colorScheme ||
|
||||
oldDelegate.textTheme != textTheme;
|
||||
}
|
||||
|
||||
TextPainter _yAxisLabel(double v) {
|
||||
|
||||
@@ -44,10 +44,7 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
],
|
||||
),
|
||||
body: _isProcessing
|
||||
? Container(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
? const QrScannerProcessingBody()
|
||||
: _importFailed
|
||||
? _buildImportFailed(context)
|
||||
: QrScannerWidget(
|
||||
@@ -55,7 +52,7 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
validator: (data) => parseContactQr(data) != null,
|
||||
onValidationFailed: (_) => _showInvalidQrError(),
|
||||
instructions: context.l10n.contacts_scanQrInstructions,
|
||||
overlay: _buildThemedOverlay(context),
|
||||
themed: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -90,73 +87,6 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildThemedOverlay(BuildContext context) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Dark semi-transparent background with cutout
|
||||
ColorFiltered(
|
||||
colorFilter: ColorFilter.mode(
|
||||
Colors.black.withValues(alpha: 0.5),
|
||||
BlendMode.srcOut,
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
backgroundBlendMode: BlendMode.dstOut,
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Container(
|
||||
height: 250,
|
||||
width: 250,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Corner brackets on top
|
||||
const ScannerCornerOverlay(
|
||||
scanWindowSize: 250,
|
||||
borderColor: MeshPalette.blue,
|
||||
borderWidth: 2,
|
||||
cornerLength: 24,
|
||||
),
|
||||
// Instructions pill below the scan window
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 250 + 24),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.72),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
),
|
||||
child: Text(
|
||||
context.l10n.contacts_scanQrInstructions,
|
||||
style: const TextStyle(color: MeshPalette.ink2, fontSize: 13),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pickFromGallery() async {
|
||||
if (_isProcessing) return;
|
||||
|
||||
@@ -291,12 +221,7 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
}
|
||||
|
||||
void _showInvalidQrError() {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_invalidAdvertFormat),
|
||||
backgroundColor: MeshPalette.warn,
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
showInvalidQrSnackBar(context, context.l10n.contacts_invalidAdvertFormat);
|
||||
}
|
||||
|
||||
void _showGalleryError() {
|
||||
|
||||
+467
-378
File diff suppressed because it is too large.
Load diff
@@ -17,13 +17,12 @@ import '../utils/contact_search.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/contact_visuals.dart';
|
||||
import '../widgets/list_filter_widget.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/node_scan_sheet.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
|
||||
enum DiscoverySortOption { lastSeen, name, type }
|
||||
|
||||
class DiscoveryScreen extends StatefulWidget {
|
||||
const DiscoveryScreen({super.key});
|
||||
|
||||
@@ -35,10 +34,9 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
String searchQuery = '';
|
||||
ContactSortOption sortOption = ContactSortOption.lastSeen;
|
||||
bool showUnreadOnly = false;
|
||||
ContactTypeFilter typeFilter = ContactTypeFilter.all;
|
||||
DiscoverySortOption discoverySortOption = DiscoverySortOption.lastSeen;
|
||||
Timer? _searchDebounce;
|
||||
final DerivedListCache<Contact> _filteredCache = DerivedListCache<Contact>();
|
||||
ScaffoldMessengerState? _messenger;
|
||||
|
||||
@override
|
||||
@@ -55,41 +53,6 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
DateTime _resolveLastSeen(Contact contact) {
|
||||
if (contact.type != advTypeChat) return contact.lastSeen;
|
||||
return contact.lastMessageAt.isAfter(contact.lastSeen)
|
||||
? contact.lastMessageAt
|
||||
: contact.lastSeen;
|
||||
}
|
||||
|
||||
/// Node-type avatar color per design language.
|
||||
Color _avatarColor(int type) {
|
||||
switch (type) {
|
||||
case advTypeRepeater:
|
||||
return MeshPalette.warn;
|
||||
case advTypeRoom:
|
||||
return MeshPalette.magenta;
|
||||
case advTypeSensor:
|
||||
return const Color(0xFF4ACCC4); // teal
|
||||
default:
|
||||
return MeshPalette.blue;
|
||||
}
|
||||
}
|
||||
|
||||
/// Node-type avatar icon; null = show initials for chat nodes.
|
||||
IconData? _avatarIcon(int type) {
|
||||
switch (type) {
|
||||
case advTypeRepeater:
|
||||
return Icons.cell_tower;
|
||||
case advTypeRoom:
|
||||
return Icons.meeting_room;
|
||||
case advTypeSensor:
|
||||
return Icons.sensors;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
@@ -231,8 +194,8 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
AvatarCircle(
|
||||
name: contact.name,
|
||||
size: 42,
|
||||
color: isChat ? null : _avatarColor(contact.type),
|
||||
icon: _avatarIcon(contact.type),
|
||||
color: isChat ? null : contactTypeColor(contact.type),
|
||||
icon: contactTypeIcon(contact.type),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
@@ -257,8 +220,8 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
const SizedBox(width: 6),
|
||||
StatusChip(
|
||||
label: contact.typeLabel(context.l10n).toUpperCase(),
|
||||
color: _avatarColor(contact.type),
|
||||
icon: _avatarIcon(contact.type),
|
||||
color: contactTypeColor(contact.type),
|
||||
icon: contactTypeIcon(contact.type),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -272,7 +235,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontSize: 12.5,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
@@ -281,20 +244,16 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
Icons.location_on,
|
||||
size: 13,
|
||||
color: scheme.onSurfaceVariant.withValues(
|
||||
alpha: 0.55,
|
||||
),
|
||||
size: 16,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
if (contact.rawPacket != null) ...[
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.cell_tower,
|
||||
size: 13,
|
||||
color: scheme.onSurfaceVariant.withValues(
|
||||
alpha: 0.55,
|
||||
),
|
||||
size: 16,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
],
|
||||
@@ -303,21 +262,26 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
// Last seen time
|
||||
MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaler: TextScaler.linear(
|
||||
MediaQuery.textScalerOf(context).scale(1.0).clamp(1.0, 1.3),
|
||||
// Last seen time. A width cap + wrapping keeps large text scales
|
||||
// from overflowing without clamping the user's text size.
|
||||
Flexible(
|
||||
flex: 0,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.sizeOf(context).width * 0.25,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
_formatLastSeen(context, _resolveLastSeen(contact)),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
color: scheme.onSurfaceVariant,
|
||||
child: Text(
|
||||
formatContactLastSeen(
|
||||
context.l10n,
|
||||
resolveContactLastSeen(contact),
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12.5,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -579,39 +543,20 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
List<Contact> filteredAndSorted,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
String hintText = "";
|
||||
switch (typeFilter) {
|
||||
case ContactTypeFilter.all:
|
||||
hintText = context.l10n.contacts_searchContacts(
|
||||
filteredAndSorted.length,
|
||||
showUnreadOnly ? " ${context.l10n.contacts_unread}" : "",
|
||||
);
|
||||
break;
|
||||
case ContactTypeFilter.users:
|
||||
hintText = context.l10n.contacts_searchUsers(
|
||||
filteredAndSorted.length,
|
||||
showUnreadOnly ? " ${context.l10n.contacts_unread}" : "",
|
||||
);
|
||||
break;
|
||||
case ContactTypeFilter.repeaters:
|
||||
hintText = context.l10n.contacts_searchRepeaters(
|
||||
filteredAndSorted.length,
|
||||
showUnreadOnly ? " ${context.l10n.contacts_unread}" : "",
|
||||
);
|
||||
break;
|
||||
case ContactTypeFilter.rooms:
|
||||
hintText = context.l10n.contacts_searchRoomServers(
|
||||
filteredAndSorted.length,
|
||||
showUnreadOnly ? " ${context.l10n.contacts_unread}" : "",
|
||||
);
|
||||
break;
|
||||
case ContactTypeFilter.favorites:
|
||||
hintText = context.l10n.contacts_searchFavorites(
|
||||
filteredAndSorted.length,
|
||||
showUnreadOnly ? " ${context.l10n.contacts_unread}" : "",
|
||||
);
|
||||
break;
|
||||
}
|
||||
final count = filteredAndSorted.length;
|
||||
final hintText = switch (typeFilter) {
|
||||
ContactTypeFilter.users => context.l10n.contacts_searchUsers(count, ''),
|
||||
ContactTypeFilter.repeaters => context.l10n.contacts_searchRepeaters(
|
||||
count,
|
||||
'',
|
||||
),
|
||||
ContactTypeFilter.rooms => context.l10n.contacts_searchRoomServers(
|
||||
count,
|
||||
'',
|
||||
),
|
||||
// Discovery offers no favorites filter; fall back to the generic hint.
|
||||
_ => context.l10n.contacts_searchContacts(count, ''),
|
||||
};
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@@ -683,27 +628,35 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
List<Contact> contacts,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
var filtered = contacts.where((contact) {
|
||||
if (searchQuery.isEmpty) return true;
|
||||
return matchesDiscoveryContactQuery(contact, searchQuery);
|
||||
// knownContactKeys returns a fresh copy; read it once per build.
|
||||
final knownKeys = connector.knownContactKeys;
|
||||
final selfKey = connector.selfPublicKey;
|
||||
final selfPubKeyHex = selfKey == null ? null : pubKeyToHex(selfKey);
|
||||
return _filteredCache.get(contacts, [
|
||||
searchQuery,
|
||||
typeFilter,
|
||||
sortOption,
|
||||
selfPubKeyHex,
|
||||
Object.hashAllUnordered(knownKeys),
|
||||
], () => _computeFilteredContacts(contacts, knownKeys, selfPubKeyHex));
|
||||
}
|
||||
|
||||
List<Contact> _computeFilteredContacts(
|
||||
List<Contact> contacts,
|
||||
Set<String> knownKeys,
|
||||
String? selfPubKeyHex,
|
||||
) {
|
||||
final filtered = contacts.where((contact) {
|
||||
if (searchQuery.isNotEmpty &&
|
||||
!matchesDiscoveryContactQuery(contact, searchQuery)) {
|
||||
return false;
|
||||
}
|
||||
if (knownKeys.contains(contact.publicKeyHex)) return false;
|
||||
// Filter out own node from the list
|
||||
if (contact.publicKeyHex == selfPubKeyHex) return false;
|
||||
return _matchesTypeFilter(contact);
|
||||
}).toList();
|
||||
|
||||
filtered = filtered.where((contact) {
|
||||
return !connector.knownContactKeys.contains(contact.publicKeyHex);
|
||||
}).toList();
|
||||
|
||||
// Filter out own node from the list
|
||||
if (connector.selfPublicKey != null) {
|
||||
final selfPubKeyHex = pubKeyToHex(connector.selfPublicKey!);
|
||||
filtered = filtered.where((contact) {
|
||||
return contact.publicKeyHex != selfPubKeyHex;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
if (typeFilter != ContactTypeFilter.all) {
|
||||
filtered = filtered.where(_matchesTypeFilter).toList();
|
||||
}
|
||||
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
@@ -730,30 +683,9 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
return contact.type == advTypeRepeater;
|
||||
case ContactTypeFilter.rooms:
|
||||
return contact.type == advTypeRoom;
|
||||
default:
|
||||
return false;
|
||||
case ContactTypeFilter.favorites:
|
||||
// Not offered by the discovery filter menu.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String _formatLastSeen(BuildContext context, DateTime lastSeen) {
|
||||
final now = DateTime.now();
|
||||
final diff = now.difference(lastSeen);
|
||||
|
||||
if (diff.isNegative || diff.inMinutes < 5) {
|
||||
return context.l10n.contacts_lastSeenNow;
|
||||
}
|
||||
if (diff.inMinutes < 60) {
|
||||
return context.l10n.contacts_lastSeenMinsAgo(diff.inMinutes);
|
||||
}
|
||||
if (diff.inHours < 24) {
|
||||
final hours = diff.inHours;
|
||||
return hours == 1
|
||||
? context.l10n.contacts_lastSeenHourAgo
|
||||
: context.l10n.contacts_lastSeenHoursAgo(hours);
|
||||
}
|
||||
final days = diff.inDays;
|
||||
return days == 1
|
||||
? context.l10n.contacts_lastSeenDayAgo
|
||||
: context.l10n.contacts_lastSeenDaysAgo(days);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
+317
-183
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
@@ -38,6 +40,11 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
bool _isLoadingCachedTiles = false;
|
||||
double _overlayZoom = 2.0;
|
||||
LatLngBounds? _visibleBounds;
|
||||
MapTileDownloadCancelToken? _cancelToken;
|
||||
// Pending camera update for the cached-tile overlay; applied after the
|
||||
// camera settles instead of on every pan frame.
|
||||
Timer? _positionDebounce;
|
||||
MapCamera? _pendingCamera;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -50,10 +57,59 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_positionDebounce?.cancel();
|
||||
_cancelToken?.cancel();
|
||||
_mapController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _useDarkOverlay => Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
Color get _overlayPanelColor => _useDarkOverlay
|
||||
? MapPalette.panelDark
|
||||
: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerLow.withValues(alpha: 0.96);
|
||||
|
||||
Color get _overlayBorderColor => _useDarkOverlay
|
||||
? MapPalette.border
|
||||
: Theme.of(context).colorScheme.outlineVariant;
|
||||
|
||||
Color get _overlayPrimaryTextColor => _useDarkOverlay
|
||||
? MapPalette.textPrimary
|
||||
: Theme.of(context).colorScheme.onSurface;
|
||||
|
||||
Color get _overlaySecondaryTextColor => _useDarkOverlay
|
||||
? MapPalette.textSecondary
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
BoxDecoration get _overlayDecoration => BoxDecoration(
|
||||
color: _overlayPanelColor,
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: _overlayBorderColor),
|
||||
);
|
||||
|
||||
void _onCameraChanged(MapCamera camera) {
|
||||
_pendingCamera = camera;
|
||||
if (_positionDebounce?.isActive ?? false) return;
|
||||
_positionDebounce = Timer(const Duration(milliseconds: 150), () {
|
||||
final next = _pendingCamera;
|
||||
if (!mounted || next == null) return;
|
||||
final nextZoom = next.zoom;
|
||||
final nextBounds = next.visibleBounds;
|
||||
if (_overlayZoom != nextZoom ||
|
||||
_visibleBounds?.north != nextBounds.north ||
|
||||
_visibleBounds?.south != nextBounds.south ||
|
||||
_visibleBounds?.east != nextBounds.east ||
|
||||
_visibleBounds?.west != nextBounds.west) {
|
||||
setState(() {
|
||||
_overlayZoom = nextZoom;
|
||||
_visibleBounds = nextBounds;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool _isDesktopPlatform(TargetPlatform platform) {
|
||||
return platform == TargetPlatform.linux ||
|
||||
platform == TargetPlatform.windows ||
|
||||
@@ -84,11 +140,7 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
top: 12,
|
||||
left: 12,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: MeshPalette.bg1.withValues(alpha: 0.90),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: MeshPalette.line2),
|
||||
),
|
||||
decoration: _overlayDecoration,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
child: Column(
|
||||
@@ -96,16 +148,19 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
color: _overlayPrimaryTextColor,
|
||||
tooltip: context.l10n.map_zoomIn,
|
||||
onPressed: () => _zoomMapBy(1),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove),
|
||||
color: _overlayPrimaryTextColor,
|
||||
tooltip: context.l10n.map_zoomOut,
|
||||
onPressed: () => _zoomMapBy(-1),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.my_location),
|
||||
color: _overlayPrimaryTextColor,
|
||||
tooltip: context.l10n.map_centerMap,
|
||||
onPressed: _resetMapView,
|
||||
),
|
||||
@@ -217,6 +272,28 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_estimatedTiles > MapTileCacheService.maxBulkDownloadTiles) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(context.l10n.mapCache_tooManyTilesTitle),
|
||||
content: Text(
|
||||
context.l10n.mapCache_tooManyTiles(
|
||||
_estimatedTiles,
|
||||
MapTileCacheService.maxBulkDownloadTiles,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_ok),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
@@ -239,16 +316,19 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
|
||||
if (confirmed != true || !mounted) return;
|
||||
|
||||
final cancelToken = MapTileDownloadCancelToken();
|
||||
setState(() {
|
||||
_isDownloading = true;
|
||||
_completedTiles = 0;
|
||||
_failedTiles = 0;
|
||||
_cancelToken = cancelToken;
|
||||
});
|
||||
|
||||
final result = await cacheService.downloadRegion(
|
||||
bounds: bounds,
|
||||
minZoom: _minZoom,
|
||||
maxZoom: _maxZoom,
|
||||
cancelToken: cancelToken,
|
||||
onProgress: (progress) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
@@ -262,11 +342,14 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
|
||||
setState(() {
|
||||
_isDownloading = false;
|
||||
_cancelToken = null;
|
||||
_completedTiles = result.downloaded + result.failed;
|
||||
_failedTiles = result.failed;
|
||||
});
|
||||
|
||||
final message = result.failed > 0
|
||||
final message = result.cancelled
|
||||
? context.l10n.mapCache_downloadCancelled(result.downloaded)
|
||||
: result.failed > 0
|
||||
? context.l10n.mapCache_cachedTilesWithFailed(
|
||||
result.downloaded,
|
||||
result.failed,
|
||||
@@ -323,12 +406,23 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
String _formatBytes(int bytes) {
|
||||
if (bytes < 1024) return '$bytes B';
|
||||
if (bytes < 1024 * 1024) {
|
||||
return '${(bytes / 1024).toStringAsFixed(1)} KB';
|
||||
void _cancelDownload() {
|
||||
_cancelToken?.cancel();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
String _formatBytes(int bytes, AppLocalizations l10n) {
|
||||
const kb = 1024;
|
||||
const mb = kb * 1024;
|
||||
const gb = mb * 1024;
|
||||
if (bytes < kb) return l10n.mapCache_sizeBytes('$bytes');
|
||||
if (bytes < mb) {
|
||||
return l10n.mapCache_sizeKilobytes((bytes / kb).toStringAsFixed(1));
|
||||
}
|
||||
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
|
||||
if (bytes < gb) {
|
||||
return l10n.mapCache_sizeMegabytes((bytes / mb).toStringAsFixed(1));
|
||||
}
|
||||
return l10n.mapCache_sizeGigabytes((bytes / gb).toStringAsFixed(2));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -354,7 +448,7 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
'${context.l10n.mapCache_summarySource(source.label)}\n'
|
||||
'${context.l10n.mapCache_summaryCachedTilesForSource(activeCachedTiles.length)}\n'
|
||||
'${context.l10n.mapCache_summaryCachedInSelection(cachedInSelection)}\n'
|
||||
'${context.l10n.mapCache_summaryApproxCacheSize(_formatBytes(_cachedTileBytes))}';
|
||||
'${context.l10n.mapCache_summaryApproxCacheSize(_formatBytes(_cachedTileBytes, context.l10n))}';
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final isDesktop = _isDesktopPlatform(defaultTargetPlatform);
|
||||
@@ -392,20 +486,8 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
)
|
||||
: const KeyboardOptions.disabled(),
|
||||
),
|
||||
onPositionChanged: (camera, hasGesture) {
|
||||
final nextZoom = camera.zoom;
|
||||
final nextBounds = camera.visibleBounds;
|
||||
if (_overlayZoom != nextZoom ||
|
||||
_visibleBounds?.north != nextBounds.north ||
|
||||
_visibleBounds?.south != nextBounds.south ||
|
||||
_visibleBounds?.east != nextBounds.east ||
|
||||
_visibleBounds?.west != nextBounds.west) {
|
||||
setState(() {
|
||||
_overlayZoom = nextZoom;
|
||||
_visibleBounds = nextBounds;
|
||||
});
|
||||
}
|
||||
},
|
||||
onPositionChanged: (camera, hasGesture) =>
|
||||
_onCameraChanged(camera),
|
||||
),
|
||||
children: [
|
||||
tileCache.buildTileLayer(context),
|
||||
@@ -415,8 +497,8 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
Polygon(
|
||||
points: _boundsToPolygon(selectedBounds),
|
||||
borderStrokeWidth: 2,
|
||||
color: Colors.blue.withValues(alpha: 0.2),
|
||||
borderColor: Colors.blue,
|
||||
color: MapPalette.selected.withValues(alpha: 0.2),
|
||||
borderColor: MapPalette.selected,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -428,12 +510,20 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
Positioned(
|
||||
top: 12,
|
||||
left: isDesktop ? 84 : 12,
|
||||
child: Card(
|
||||
child: DecoratedBox(
|
||||
decoration: _overlayDecoration,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 8,
|
||||
),
|
||||
child: Text(
|
||||
'Z: ${_overlayZoom.round()}:',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
l10n.mapCache_zoomLevel(_overlayZoom.round()),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _overlayPrimaryTextColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -441,24 +531,24 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
Positioned(
|
||||
top: 12,
|
||||
right: 12,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: MeshPalette.bg1.withValues(alpha: 0.93),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: MeshPalette.line2),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 6,
|
||||
),
|
||||
child: Text(
|
||||
selectedBounds == null
|
||||
? l10n.mapCache_noAreaSelected
|
||||
: _formatBounds(selectedBounds, l10n),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
color: MeshPalette.ink2,
|
||||
left: isDesktop ? 200 : 130,
|
||||
child: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: DecoratedBox(
|
||||
decoration: _overlayDecoration,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 6,
|
||||
),
|
||||
child: Text(
|
||||
selectedBounds == null
|
||||
? l10n.mapCache_noAreaSelected
|
||||
: _formatBounds(selectedBounds, l10n),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: _overlaySecondaryTextColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -474,158 +564,202 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
color: scheme.surfaceContainerLow,
|
||||
border: Border(top: BorderSide(color: scheme.outlineVariant)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SectionHeader(
|
||||
l10n.mapCache_cacheArea,
|
||||
padding: const EdgeInsets.fromLTRB(0, 12, 0, 8),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.crop_free),
|
||||
label: Text(l10n.mapCache_useCurrentView),
|
||||
onPressed: _isDownloading
|
||||
? null
|
||||
: _setBoundsFromView,
|
||||
// Cap the panel so the map keeps room in landscape; the controls
|
||||
// scroll inside it.
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.5,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SectionHeader(
|
||||
l10n.mapCache_cacheArea,
|
||||
padding: const EdgeInsets.fromLTRB(0, 12, 0, 8),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.crop_free),
|
||||
label: Text(l10n.mapCache_useCurrentView),
|
||||
onPressed: _isDownloading
|
||||
? null
|
||||
: _setBoundsFromView,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
TextButton(
|
||||
onPressed: _isDownloading || selectedBounds == null
|
||||
? null
|
||||
: _clearBounds,
|
||||
child: Text(l10n.common_clear),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SectionHeader(
|
||||
l10n.mapCache_zoomRange,
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 0),
|
||||
),
|
||||
RangeSlider(
|
||||
values: RangeValues(
|
||||
_minZoom.toDouble(),
|
||||
_maxZoom.toDouble(),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
TextButton(
|
||||
onPressed: _isDownloading || selectedBounds == null
|
||||
? null
|
||||
: _clearBounds,
|
||||
child: Text(l10n.common_clear),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SectionHeader(
|
||||
l10n.mapCache_zoomRange,
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 0),
|
||||
),
|
||||
RangeSlider(
|
||||
values: RangeValues(
|
||||
_minZoom.toDouble(),
|
||||
_maxZoom.toDouble(),
|
||||
min: 3,
|
||||
max: 18,
|
||||
divisions: 15,
|
||||
labels: RangeLabels('$_minZoom', '$_maxZoom'),
|
||||
onChanged: _isDownloading
|
||||
? null
|
||||
: (values) {
|
||||
setState(() {
|
||||
_minZoom = values.start.round();
|
||||
_maxZoom = values.end.round();
|
||||
});
|
||||
},
|
||||
onChangeEnd: _isDownloading
|
||||
? null
|
||||
: (_) {
|
||||
_saveZoomRange();
|
||||
},
|
||||
),
|
||||
min: 3,
|
||||
max: 18,
|
||||
divisions: 15,
|
||||
labels: RangeLabels('$_minZoom', '$_maxZoom'),
|
||||
onChanged: _isDownloading
|
||||
? null
|
||||
: (values) {
|
||||
setState(() {
|
||||
_minZoom = values.start.round();
|
||||
_maxZoom = values.end.round();
|
||||
});
|
||||
},
|
||||
onChangeEnd: _isDownloading
|
||||
? null
|
||||
: (_) {
|
||||
_saveZoomRange();
|
||||
},
|
||||
),
|
||||
Text(
|
||||
l10n.mapCache_estimatedTiles(_estimatedTiles),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
key: ValueKey(
|
||||
'$cacheSummary|${activeCachedTiles.length}|$cachedInSelection|$_cachedTileBytes',
|
||||
),
|
||||
initialValue: cacheSummary,
|
||||
readOnly: true,
|
||||
minLines: 4,
|
||||
maxLines: 4,
|
||||
decoration: InputDecoration(
|
||||
labelText: _isLoadingCachedTiles
|
||||
? l10n.mapCache_cachedTilesLabel
|
||||
: l10n.mapCache_cachedTileSummaryLabel,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
if (!source.allowsBulkDownload) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.mapCache_bulkDownloadDisabledForSource(
|
||||
source.label,
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: MeshPalette.alert,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_isDownloading) ...[
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(
|
||||
value: progressValue,
|
||||
color: MeshPalette.blue,
|
||||
backgroundColor: scheme.surfaceContainerHighest,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.mapCache_downloadedTiles(
|
||||
_completedTiles,
|
||||
_estimatedTiles,
|
||||
),
|
||||
l10n.mapCache_estimatedTiles(_estimatedTiles),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.download),
|
||||
label: Text(l10n.mapCache_downloadTilesButton),
|
||||
onPressed:
|
||||
_isDownloading ||
|
||||
selectedBounds == null ||
|
||||
!source.allowsBulkDownload
|
||||
? null
|
||||
: _startDownload,
|
||||
const SizedBox(height: 12),
|
||||
if (_estimatedTiles >
|
||||
MapTileCacheService.maxBulkDownloadTiles) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.mapCache_tooManyTiles(
|
||||
_estimatedTiles,
|
||||
MapTileCacheService.maxBulkDownloadTiles,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
OutlinedButton(
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: MeshPalette.alert,
|
||||
side: const BorderSide(
|
||||
color: MeshPalette.alertLine,
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.alert,
|
||||
),
|
||||
onPressed: _isDownloading ? null : _clearCache,
|
||||
child: Text(l10n.mapCache_clearCacheButton),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_failedTiles > 0 && !_isDownloading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
l10n.mapCache_failedDownloads(_failedTiles),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
_isLoadingCachedTiles
|
||||
? l10n.mapCache_cachedTilesLabel
|
||||
: l10n.mapCache_cachedTileSummaryLabel,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
MeshCard(
|
||||
margin: EdgeInsets.zero,
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: SelectableText(
|
||||
cacheSummary,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!source.allowsBulkDownload) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.mapCache_bulkDownloadDisabledForSource(
|
||||
source.label,
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: MeshPalette.alert,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_isDownloading) ...[
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(
|
||||
value: progressValue,
|
||||
color: MeshPalette.blue,
|
||||
backgroundColor: scheme.surfaceContainerHighest,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.mapCache_downloadedTiles(
|
||||
_completedTiles,
|
||||
_estimatedTiles,
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _isDownloading
|
||||
? OutlinedButton.icon(
|
||||
icon: const Icon(
|
||||
Icons.stop_circle_outlined,
|
||||
),
|
||||
label: Text(l10n.common_cancel),
|
||||
onPressed:
|
||||
(_cancelToken?.isCancelled ?? true)
|
||||
? null
|
||||
: _cancelDownload,
|
||||
)
|
||||
: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.download),
|
||||
label: Text(
|
||||
l10n.mapCache_downloadTilesButton,
|
||||
),
|
||||
onPressed:
|
||||
selectedBounds == null ||
|
||||
!source.allowsBulkDownload
|
||||
? null
|
||||
: _startDownload,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
OutlinedButton(
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: MeshPalette.alert,
|
||||
side: const BorderSide(
|
||||
color: MeshPalette.alertLine,
|
||||
),
|
||||
),
|
||||
onPressed: _isDownloading ? null : _clearCache,
|
||||
child: Text(l10n.mapCache_clearCacheButton),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (_failedTiles > 0 && !_isDownloading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
l10n.mapCache_failedDownloads(_failedTiles),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: MeshPalette.alert,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
+597
-257
File diff suppressed because it is too large.
Load diff
@@ -14,6 +14,9 @@ import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../widgets/repeater_login_dialog.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
|
||||
class NeighborsScreen extends StatefulWidget {
|
||||
final Contact repeater;
|
||||
@@ -100,22 +103,22 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
String fmtDuration(double seconds) {
|
||||
static String fmtDuration(AppLocalizations l10n, double seconds) {
|
||||
if (seconds < 60) {
|
||||
return '${seconds.toStringAsFixed(1)}s';
|
||||
return l10n.neighbors_durationSeconds(seconds.toStringAsFixed(1));
|
||||
}
|
||||
|
||||
final int m = (seconds ~/ 60).toInt();
|
||||
final double s = seconds - (60 * m);
|
||||
|
||||
if (m < 60) {
|
||||
return '${m}m ${s.toStringAsFixed(0)}s';
|
||||
return l10n.neighbors_durationMinutes(m, s.toStringAsFixed(0));
|
||||
}
|
||||
|
||||
final int h = m ~/ 60;
|
||||
final int m2 = m % 60;
|
||||
|
||||
return '${h}h ${m2}m';
|
||||
return l10n.neighbors_durationHours(h, m2);
|
||||
}
|
||||
|
||||
static List<Map<String, dynamic>> parseNeighborsData(
|
||||
@@ -184,11 +187,6 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
_loadNeighbors(offset: parsedNeighbors.length);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.neighbors_receivedData),
|
||||
backgroundColor: Theme.of(context).colorScheme.tertiary,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = true;
|
||||
@@ -343,7 +341,22 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),
|
||||
children: [
|
||||
if (!_isLoaded &&
|
||||
// First request still in flight: show progress, not "no data".
|
||||
if (_isLoading && _parsedNeighbors == null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 64),
|
||||
child: Column(
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
l10n.common_loading,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
else if (!_isLoaded &&
|
||||
!_hasData &&
|
||||
(_parsedNeighbors == null || _parsedNeighbors!.isEmpty))
|
||||
EmptyState(icon: Icons.wifi_find, title: l10n.neighbors_noData),
|
||||
@@ -391,12 +404,15 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
|
||||
final snrColor = MeshTheme.snrColor(snr, blocked: false);
|
||||
final heardLabel = l10n.neighbors_heardAgo(
|
||||
fmtDuration(lastHeardSeconds + 0.0),
|
||||
fmtDuration(l10n, lastHeardSeconds + 0.0),
|
||||
);
|
||||
// Only repeaters saved on the radio can be logged into.
|
||||
final canOpen = contact != null && contact.isActive;
|
||||
|
||||
return MeshCard(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
onTap: canOpen ? () => _openNeighbor(contact) : null,
|
||||
child: Row(
|
||||
children: [
|
||||
AvatarCircle(
|
||||
@@ -426,7 +442,7 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontSize: 13,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
@@ -443,15 +459,43 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
Text(
|
||||
'${snr.toStringAsFixed(1)} dB',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: snrColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (canOpen) ...[
|
||||
const SizedBox(width: 4),
|
||||
Icon(Icons.chevron_right, size: 24, color: scheme.onSurfaceVariant),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Opens a resolved neighbor the same way the contacts list does:
|
||||
/// repeaters go through the login dialog to the repeater hub.
|
||||
void _openNeighbor(Contact contact) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => RepeaterLoginDialog(
|
||||
repeater: contact,
|
||||
onLogin: (password, isAdmin) {
|
||||
if (!mounted) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => RepeaterHubScreen(
|
||||
repeater: contact,
|
||||
password: password,
|
||||
isAdmin: isAdmin,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+172
-324
@@ -18,6 +18,8 @@ import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/map_tile_cache_service.dart';
|
||||
import 'package:meshcore_open/services/path_history_service.dart';
|
||||
import 'package:meshcore_open/utils/app_logger.dart';
|
||||
import 'package:meshcore_open/helpers/snack_bar_builder.dart';
|
||||
import 'package:meshcore_open/widgets/path_map_scaffold.dart';
|
||||
import 'package:meshcore_open/widgets/path_map_ui.dart';
|
||||
import 'package:meshcore_open/widgets/snr_indicator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -80,9 +82,9 @@ class PathTraceMapScreen extends StatefulWidget {
|
||||
|
||||
class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
static const double _labelZoomThreshold = 8.5;
|
||||
static const double _mapMinZoom = 2.0;
|
||||
static const double _mapMaxZoom = 18.0;
|
||||
static const double _labelZoomThreshold = kPathMapLabelZoomThreshold;
|
||||
// Used when the radio never acknowledges the trace request.
|
||||
static const Duration _sendAckTimeout = Duration(seconds: 15);
|
||||
//miles to meters conversion for filtering out repeaters that are too far from the last known GPS hop to be a likely match, to avoid false matches that throw off the inferred positions of other hops in the path
|
||||
static const double _maxRepeaterMatchDistanceMeters = 40 * 1609.344;
|
||||
|
||||
@@ -130,6 +132,10 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
bool _animationEnabled = true;
|
||||
bool _followPacket = false;
|
||||
|
||||
// Hop-prefix -> contact lookups, invalidated when the contact list changes.
|
||||
final Map<String, Contact?> _hopContactCache = {};
|
||||
int? _hopContactCacheSignature;
|
||||
|
||||
String _formatPathPrefixes(Uint8List pathBytes, [int? hashByteWidth]) {
|
||||
return PathHelper.splitPathBytes(
|
||||
pathBytes,
|
||||
@@ -235,15 +241,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
|
||||
/// Keeps the camera centered on the packet while the follow lock is on.
|
||||
void _followPacketCamera() {
|
||||
if (!_followPacket ||
|
||||
!_animationEnabled ||
|
||||
!_playback.started ||
|
||||
!_playback.hasPath ||
|
||||
!mounted ||
|
||||
!_hasData) {
|
||||
return;
|
||||
}
|
||||
_mapController.move(_playback.position, _mapController.camera.zoom);
|
||||
if (!mounted) return;
|
||||
followPacketCamera(
|
||||
_mapController,
|
||||
_playback,
|
||||
enabled: _followPacket && _animationEnabled && _hasData,
|
||||
);
|
||||
}
|
||||
|
||||
void _toggleFollowPacket() {
|
||||
@@ -253,72 +256,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
_followPacketCamera();
|
||||
}
|
||||
|
||||
bool _isDesktopPlatform(TargetPlatform platform) {
|
||||
return platform == TargetPlatform.linux ||
|
||||
platform == TargetPlatform.windows ||
|
||||
platform == TargetPlatform.macOS;
|
||||
}
|
||||
|
||||
void _zoomMapBy(double delta) {
|
||||
final camera = _mapController.camera;
|
||||
final nextZoom = (camera.zoom + delta)
|
||||
.clamp(_mapMinZoom, _mapMaxZoom)
|
||||
.toDouble();
|
||||
_mapController.move(camera.center, nextZoom);
|
||||
}
|
||||
|
||||
void _resetMapView() {
|
||||
final bounds = _bounds;
|
||||
if (bounds != null) {
|
||||
_mapController.fitCamera(
|
||||
CameraFit.bounds(
|
||||
bounds: bounds,
|
||||
padding: const EdgeInsets.all(64),
|
||||
maxZoom: 16,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final center = _initialCenter;
|
||||
if (center != null) {
|
||||
_mapController.move(center, _initialZoom);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildDesktopMapControls() {
|
||||
return Positioned(
|
||||
top: 16,
|
||||
left: 16,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: MeshPalette.bg1.withValues(alpha: 0.90),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: MeshPalette.line2),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
tooltip: context.l10n.map_zoomIn,
|
||||
onPressed: () => _zoomMapBy(1),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove),
|
||||
tooltip: context.l10n.map_zoomOut,
|
||||
onPressed: () => _zoomMapBy(-1),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.my_location),
|
||||
tooltip: context.l10n.map_centerMap,
|
||||
onPressed: _resetMapView,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
resetMapView(
|
||||
_mapController,
|
||||
bounds: _bounds,
|
||||
center: _initialCenter,
|
||||
zoom: _initialZoom,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -469,7 +412,37 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
payload: tracePayload,
|
||||
);
|
||||
_awaitingTraceSent = true;
|
||||
connector.sendFrame(frame);
|
||||
_timeoutTimer?.cancel();
|
||||
// Fallback in case RESP_CODE_SENT / RESP_CODE_ERR never arrives; the
|
||||
// RESP_CODE_SENT handler replaces it with the radio's own timeout.
|
||||
_timeoutTimer = Timer(_sendAckTimeout, () {
|
||||
if (!mounted || !_awaitingTraceSent) return;
|
||||
_awaitingTraceSent = false;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_failed2Loaded = true;
|
||||
});
|
||||
});
|
||||
try {
|
||||
await connector.sendFrame(frame);
|
||||
} catch (e) {
|
||||
_awaitingTraceSent = false;
|
||||
_timeoutTimer?.cancel();
|
||||
appLogger.error(
|
||||
'Failed to send path trace: $e',
|
||||
tag: 'PathTraceMapScreen',
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_failed2Loaded = true;
|
||||
});
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.pathTrace_sendFailed(e.toString())),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _setupFrameListener() {
|
||||
@@ -725,7 +698,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
_targetContactIsGuessed = targetGuessed;
|
||||
|
||||
_points = <LatLng>[];
|
||||
_points.add(LatLng(connector.selfLatitude!, connector.selfLongitude!));
|
||||
final selfPoint = plausibleSelfPoint(connector);
|
||||
if (selfPoint != null) _points.add(selfPoint);
|
||||
String hopLast = '';
|
||||
String hopLastLast = '';
|
||||
for (final hop in _traceData!.pathData) {
|
||||
@@ -753,7 +727,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Polyline(
|
||||
points: _points,
|
||||
strokeWidth: 4,
|
||||
color: Colors.blueAccent,
|
||||
color: kPrimaryPathColor,
|
||||
),
|
||||
]
|
||||
: <Polyline>[];
|
||||
@@ -801,16 +775,31 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
}
|
||||
|
||||
Contact? _contactForHop(Uint8List hop, MeshCoreConnector connector) {
|
||||
final traced = _traceData?.pathContacts[_hopKey(hop)];
|
||||
final hopKey = _hopKey(hop);
|
||||
final traced = _traceData?.pathContacts[hopKey];
|
||||
if (traced != null) return traced;
|
||||
for (final c in connector.allContactsUnfiltered) {
|
||||
if (c.type != advTypeChat &&
|
||||
c.publicKey.length >= hop.length &&
|
||||
listEquals(c.publicKey.sublist(0, hop.length), hop)) {
|
||||
return c;
|
||||
_hopContactCacheSignature ??= _refreshHopContactCache(connector);
|
||||
return _hopContactCache.putIfAbsent(hopKey, () {
|
||||
for (final c in connector.allContactsUnfiltered) {
|
||||
if (c.type != advTypeChat &&
|
||||
c.publicKey.length >= hop.length &&
|
||||
listEquals(c.publicKey.sublist(0, hop.length), hop)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/// Drops cached hop -> contact lookups when the contact list changed;
|
||||
/// called once per build so per-hop lookups stay cheap.
|
||||
int _refreshHopContactCache(MeshCoreConnector connector) {
|
||||
final signature = contactListSignature(connector.allContactsUnfiltered);
|
||||
if (signature != _hopContactCacheSignature) {
|
||||
_hopContactCache.clear();
|
||||
_hopContactCacheSignature = signature;
|
||||
}
|
||||
return null;
|
||||
return signature;
|
||||
}
|
||||
|
||||
LatLng? _inferredPositionForHop(Uint8List hop, MeshCoreConnector connector) {
|
||||
@@ -842,6 +831,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
/// Rebuilds the renderable paths: the traced path as primary plus up to
|
||||
/// four distinct alternates from the target contact's path history.
|
||||
void _rebuildDisplayPaths(MeshCoreConnector connector) {
|
||||
_refreshHopContactCache(connector);
|
||||
final paths = <DisplayPath>[];
|
||||
final primary = _buildDisplayPath(
|
||||
id: 'primary',
|
||||
@@ -900,15 +890,14 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
required MeshCoreConnector connector,
|
||||
PathRecord? record,
|
||||
}) {
|
||||
final selfLat = connector.selfLatitude;
|
||||
final selfLon = connector.selfLongitude;
|
||||
if (selfLat == null || selfLon == null) return null;
|
||||
|
||||
final points = <LatLng>[LatLng(selfLat, selfLon)];
|
||||
final labels = <String>[context.l10n.pathTrace_you];
|
||||
final confirmed = <bool>[true];
|
||||
final hopOrdinals = <int>[-1];
|
||||
final gapBefore = <bool>[false];
|
||||
// Without a GPS fix for the local radio the path starts at the first
|
||||
// located hop instead of a bogus "You" at 0,0.
|
||||
final selfPoint = plausibleSelfPoint(connector);
|
||||
final points = <LatLng>[?selfPoint];
|
||||
final labels = <String>[if (selfPoint != null) context.l10n.pathTrace_you];
|
||||
final confirmed = <bool>[if (selfPoint != null) true];
|
||||
final hopOrdinals = <int>[if (selfPoint != null) -1];
|
||||
final gapBefore = <bool>[if (selfPoint != null) false];
|
||||
int gpsConfirmedHops = 0;
|
||||
int unresolvedHops = 0;
|
||||
bool pendingGap = false;
|
||||
@@ -1004,18 +993,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
/// actually changed, so unrelated path-history updates don't reset a
|
||||
/// running animation.
|
||||
void _syncPlaybackToSelection() {
|
||||
final points = _selectedPath?.points ?? const <LatLng>[];
|
||||
if (points.length == _playback.points.length) {
|
||||
var same = true;
|
||||
for (var i = 0; i < points.length; i++) {
|
||||
if (points[i] != _playback.points[i]) {
|
||||
same = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (same) return;
|
||||
}
|
||||
_playback.setPath(points);
|
||||
syncPlaybackPath(_playback, _selectedPath?.points ?? const <LatLng>[]);
|
||||
}
|
||||
|
||||
void _selectPath(DisplayPath path) {
|
||||
@@ -1047,6 +1025,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
if (_hasData) _refreshHopContactCache(connector);
|
||||
final settings = context.watch<AppSettingsService>().settings;
|
||||
final isImperial = settings.unitSystem == UnitSystem.imperial;
|
||||
final tileCache = context.read<MapTileCacheService>();
|
||||
@@ -1092,8 +1071,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
),
|
||||
if (_hasData)
|
||||
_buildMapPathTrace(context, tileCache, _targetContact),
|
||||
if (_hasData && _isDesktopPlatform(defaultTargetPlatform))
|
||||
_buildDesktopMapControls(),
|
||||
if (_hasData && isDesktopMapPlatform())
|
||||
PathMapDesktopControls(
|
||||
onZoomIn: () => zoomMapBy(_mapController, 1),
|
||||
onZoomOut: () => zoomMapBy(_mapController, -1),
|
||||
onReset: _resetMapView,
|
||||
),
|
||||
if (_hasData && _displayPaths.length > 1)
|
||||
PathViewModeToggle(
|
||||
mode: _viewMode,
|
||||
@@ -1202,7 +1185,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
),
|
||||
);
|
||||
if (showLabels) {
|
||||
markers.add(_buildNodeLabelMarker(point: point, label: fullLabel));
|
||||
markers.add(buildPathNodeLabelMarker(point: point, label: fullLabel));
|
||||
}
|
||||
hopLastLast = hopLast;
|
||||
hopLast = hopKey;
|
||||
@@ -1219,10 +1202,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
required bool showLabels,
|
||||
required Contact? target,
|
||||
}) {
|
||||
final selfLat = context.read<MeshCoreConnector>().selfLatitude;
|
||||
final selfLon = context.read<MeshCoreConnector>().selfLongitude;
|
||||
if (selfLat != null && selfLon != null) {
|
||||
final selfPoint = LatLng(selfLat, selfLon);
|
||||
final selfPoint = plausibleSelfPoint(context.read<MeshCoreConnector>());
|
||||
if (selfPoint != null) {
|
||||
markers.add(
|
||||
Marker(
|
||||
point: selfPoint,
|
||||
@@ -1247,12 +1228,16 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
],
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
context.l10n.pathTrace_you,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: MeshPalette.blue,
|
||||
padding: const EdgeInsets.all(3),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
context.l10n.pathTrace_you,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: MeshPalette.blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1261,7 +1246,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
if (showLabels) {
|
||||
markers.add(
|
||||
_buildNodeLabelMarker(
|
||||
buildPathNodeLabelMarker(
|
||||
point: selfPoint,
|
||||
label: context.l10n.pathTrace_you,
|
||||
),
|
||||
@@ -1315,7 +1300,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
if (showLabels) {
|
||||
markers.add(
|
||||
_buildNodeLabelMarker(
|
||||
buildPathNodeLabelMarker(
|
||||
point: targetPos,
|
||||
label: isGuessed ? '~$targetName' : targetName,
|
||||
),
|
||||
@@ -1388,12 +1373,16 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
],
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
hasGps ? label : '~$label',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: baseColor,
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
hasGps ? label : '~$label',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: baseColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1401,24 +1390,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 17,
|
||||
height: 17,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: MeshPalette.bg1,
|
||||
border: Border.all(color: MeshPalette.line3),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'${paths.length}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: MeshPalette.ink,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: PathSharedCountBadge(count: paths.length),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1427,7 +1399,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
if (showLabels) {
|
||||
markers.add(
|
||||
_buildNodeLabelMarker(
|
||||
buildPathNodeLabelMarker(
|
||||
point: point,
|
||||
label: contact?.name ?? '~$label',
|
||||
),
|
||||
@@ -1455,42 +1427,6 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Marker _buildNodeLabelMarker({required LatLng point, required String label}) {
|
||||
return Marker(
|
||||
point: point,
|
||||
width: 120,
|
||||
height: 24,
|
||||
alignment: Alignment.topCenter,
|
||||
child: IgnorePointer(
|
||||
child: Transform.translate(
|
||||
offset: const Offset(0, -20),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: MeshPalette.bg.withValues(alpha: 0.82),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.xs),
|
||||
border: Border.all(color: MeshPalette.line, width: 0.5),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: MeshPalette.ink2,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String formatDirectionText(PathTraceData pathTraceData, int index) {
|
||||
if (pathTraceData.pathData.isEmpty) {
|
||||
return context.l10n.pathTrace_you;
|
||||
@@ -1554,35 +1490,13 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
MapTileCacheService tileCache,
|
||||
Contact? target,
|
||||
) {
|
||||
final isDesktop = _isDesktopPlatform(defaultTargetPlatform);
|
||||
return FlutterMap(
|
||||
key: _mapKey,
|
||||
mapController: _mapController,
|
||||
options: MapOptions(
|
||||
interactionOptions: InteractionOptions(
|
||||
flags: ~InteractiveFlag.rotate,
|
||||
scrollWheelVelocity: isDesktop ? 0.012 : 0.005,
|
||||
cursorKeyboardRotationOptions:
|
||||
CursorKeyboardRotationOptions.disabled(),
|
||||
keyboardOptions: isDesktop
|
||||
? const KeyboardOptions(
|
||||
enableArrowKeysPanning: true,
|
||||
enableWASDPanning: true,
|
||||
enableRFZooming: true,
|
||||
)
|
||||
: const KeyboardOptions.disabled(),
|
||||
),
|
||||
options: buildPathMapOptions(
|
||||
initialCenter: _initialCenter!,
|
||||
initialZoom: _initialZoom,
|
||||
initialCameraFit: _bounds == null
|
||||
? null
|
||||
: CameraFit.bounds(
|
||||
bounds: _bounds!,
|
||||
padding: const EdgeInsets.all(64),
|
||||
maxZoom: 16,
|
||||
),
|
||||
minZoom: _mapMinZoom,
|
||||
maxZoom: _mapMaxZoom,
|
||||
bounds: _bounds,
|
||||
onPositionChanged: (camera, hasGesture) {
|
||||
if (!mounted) return;
|
||||
// A manual pan/zoom releases the follow lock.
|
||||
@@ -1674,118 +1588,49 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
final l10n = context.l10n;
|
||||
final selected = _selectedPath;
|
||||
final combined = _viewMode == PathViewMode.combined;
|
||||
final maxHeight =
|
||||
MediaQuery.of(context).size.height * (combined ? 0.45 : 0.35);
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final hopRows = combined
|
||||
? (selected?.totalTransmissions ?? 0)
|
||||
: pathTraceData.pathData.length + 1;
|
||||
|
||||
double cardHeight;
|
||||
if (_panelCollapsed) {
|
||||
cardHeight = 128;
|
||||
} else {
|
||||
final summaryHeight = combined ? 34.0 + _displayPaths.length * 36.0 : 0;
|
||||
final hopRows = combined
|
||||
? (selected?.totalTransmissions ?? 0)
|
||||
: pathTraceData.pathData.length + 1;
|
||||
final estimatedHeight = 132.0 + summaryHeight + hopRows * 56.0;
|
||||
cardHeight = max(176.0, min(maxHeight, estimatedHeight));
|
||||
}
|
||||
|
||||
return Positioned(
|
||||
left: 16,
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
child: SizedBox(
|
||||
height: cardHeight,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: MeshPalette.bg1.withValues(alpha: 0.95),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: MeshPalette.line2),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 4, 0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${l10n.channelPath_repeaterHops} ${formatDistance(selected?.distanceMeters ?? _pathDistanceMeters, isImperial: isImperial)}',
|
||||
style: MeshTheme.mono(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
color: MeshPalette.ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
PathMiniLegend(combined: combined),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
icon: Icon(
|
||||
_panelCollapsed
|
||||
? Icons.expand_less
|
||||
: Icons.expand_more,
|
||||
size: 20,
|
||||
),
|
||||
tooltip: _panelCollapsed
|
||||
? l10n.pathMap_expandPanel
|
||||
: l10n.pathMap_collapsePanel,
|
||||
onPressed: () =>
|
||||
setState(() => _panelCollapsed = !_panelCollapsed),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PathAnimationControls(
|
||||
playback: _playback,
|
||||
selected: selected,
|
||||
animationEnabled: _animationEnabled,
|
||||
onToggleAnimation: () => setState(() {
|
||||
_animationEnabled = !_animationEnabled;
|
||||
if (!_animationEnabled) _playback.stop();
|
||||
}),
|
||||
followEnabled: _followPacket,
|
||||
onToggleFollow: _toggleFollowPacket,
|
||||
),
|
||||
if (!_panelCollapsed) ...[
|
||||
if (selected != null && selected.unresolvedHops > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 0, 12, 4),
|
||||
child: Text(
|
||||
l10n.pathMap_partialAnimation(selected.unresolvedHops),
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: MeshPalette.warn,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (combined)
|
||||
PathSummaryList(
|
||||
paths: _displayPaths,
|
||||
selectedId: _selectedPathId,
|
||||
hiddenIds: _hiddenPathIds,
|
||||
isImperial: isImperial,
|
||||
onSelect: _selectPath,
|
||||
onToggleVisibility: _togglePathVisibility,
|
||||
onShowAll: () => setState(_hiddenPathIds.clear),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Expanded(child: _buildHopList(pathTraceData, selected)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
return PathMapBottomPanel(
|
||||
header: Text(
|
||||
'${l10n.channelPath_repeaterHops} ${formatDistance(selected?.distanceMeters ?? _pathDistanceMeters, isImperial: isImperial, l10n: l10n)}',
|
||||
style: MeshTheme.mono(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
color: MeshPalette.ink,
|
||||
),
|
||||
),
|
||||
combined: combined,
|
||||
showInferredLegend: true,
|
||||
collapsed: _panelCollapsed,
|
||||
onToggleCollapsed: () =>
|
||||
setState(() => _panelCollapsed = !_panelCollapsed),
|
||||
playback: _playback,
|
||||
selected: selected,
|
||||
animationEnabled: _animationEnabled,
|
||||
onToggleAnimation: () => setState(() {
|
||||
_animationEnabled = !_animationEnabled;
|
||||
if (!_animationEnabled) _playback.stop();
|
||||
}),
|
||||
followEnabled: _followPacket,
|
||||
onToggleFollow: _toggleFollowPacket,
|
||||
showNoSelfGpsNote: plausibleSelfPoint(connector) == null,
|
||||
pathCount: _displayPaths.length,
|
||||
hopRowCount: hopRows,
|
||||
summary: combined
|
||||
? PathSummaryList(
|
||||
paths: _displayPaths,
|
||||
selectedId: _selectedPathId,
|
||||
hiddenIds: _hiddenPathIds,
|
||||
isImperial: isImperial,
|
||||
onSelect: _selectPath,
|
||||
onToggleVisibility: _togglePathVisibility,
|
||||
onShowAll: () => setState(_hiddenPathIds.clear),
|
||||
)
|
||||
: null,
|
||||
hopList: _buildHopList(pathTraceData, selected),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1836,9 +1681,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
tileColor: index == highlightRow
|
||||
? kPrimaryPathColor.withValues(alpha: 0.14)
|
||||
: null,
|
||||
leading: index >= pathTraceData.snrData.length / 2
|
||||
? Icon(Icons.call_received)
|
||||
: Icon(Icons.call_made),
|
||||
leading: Icon(
|
||||
index >= pathTraceData.snrData.length / 2
|
||||
? Icons.call_received
|
||||
: Icons.call_made,
|
||||
color: MeshPalette.ink2,
|
||||
),
|
||||
title: Text(
|
||||
formatDirectionText(pathTraceData, index),
|
||||
style: MeshTheme.mono(fontSize: 13, color: MeshPalette.ink),
|
||||
@@ -1853,7 +1701,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Icon(snrUi.icon, color: snrUi.color, size: 18.0),
|
||||
Text(
|
||||
snrUi.text,
|
||||
style: MeshTheme.mono(fontSize: 10, color: snrUi.color),
|
||||
style: MeshTheme.mono(fontSize: 12, color: snrUi.color),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1919,7 +1767,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Icon(snrUi.icon, color: snrUi.color, size: 18.0),
|
||||
Text(
|
||||
snrUi.text,
|
||||
style: MeshTheme.mono(fontSize: 10, color: snrUi.color),
|
||||
style: MeshTheme.mono(fontSize: 12, color: snrUi.color),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -1946,7 +1794,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
child: Text(
|
||||
'${index + 1}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: path.color,
|
||||
),
|
||||
@@ -1958,7 +1806,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: MeshTheme.mono(fontSize: 11, color: MeshPalette.ink3),
|
||||
style: MeshTheme.mono(fontSize: 12, color: MeshPalette.ink3),
|
||||
),
|
||||
trailing: trailing,
|
||||
);
|
||||
|
||||
@@ -36,6 +36,22 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
List<Region> _regions = [];
|
||||
bool _isFetchingRegions = false;
|
||||
|
||||
/// Completed when the user cancels an in-progress fetch; pending discovery
|
||||
/// and region requests resolve immediately with no results.
|
||||
Completer<void>? _fetchCancel;
|
||||
|
||||
/// Drives the fetch progress dialog: null while discovering, otherwise
|
||||
/// (current repeater, total repeaters).
|
||||
final ValueNotifier<(int, int)?> _fetchProgress = ValueNotifier(null);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
final cancel = _fetchCancel;
|
||||
if (cancel != null && !cancel.isCompleted) cancel.complete();
|
||||
_fetchProgress.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -114,6 +130,9 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Keep the app default visible so "No region (unscoped)" can be
|
||||
// chosen before any region is added.
|
||||
_buildDefaultRegionTile(context),
|
||||
// The radio may hold a default region set by firmware or another
|
||||
// client even when this app's list is empty; keep it clearable.
|
||||
_buildRadioDefaultRegionTile(context),
|
||||
@@ -245,52 +264,105 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _showAddRegionDialog(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
Future<void> _showAddRegionDialog(BuildContext context) async {
|
||||
final region = await showDialog<Region>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(l10n.settings_regionName),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.send,
|
||||
onSubmitted: (_) => _handleAddRegion(controller.text, context),
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.settings_regionNameHint,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.allow(RegExp("[a-z0-9-]")),
|
||||
],
|
||||
maxLength: 30,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => _handleAddRegion(controller.text, context),
|
||||
child: Text(l10n.common_add),
|
||||
),
|
||||
],
|
||||
),
|
||||
builder: (_) => const _AddRegionDialog(),
|
||||
);
|
||||
if (region == null || !mounted) return;
|
||||
_handleAddRegion(region);
|
||||
}
|
||||
|
||||
Future<void> _showFetchRegionsDialog() async {
|
||||
if (_isFetchingRegions) return;
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
|
||||
if (!connector.isConnected) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_notConnectedError),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final knownRepeaters = connector.contacts
|
||||
.where((contact) => contact.type == advTypeRepeater)
|
||||
.toList();
|
||||
if (knownRepeaters.isEmpty) {
|
||||
await _showFetchMessage(l10n.settings_regionFetchNoRepeaters);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isFetchingRegions = true;
|
||||
});
|
||||
final cancel = Completer<void>();
|
||||
_fetchCancel = cancel;
|
||||
_fetchProgress.value = null;
|
||||
|
||||
Set<Region> fetchedRegions = {};
|
||||
BuildContext? progressContext;
|
||||
unawaited(
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) {
|
||||
progressContext = dialogContext;
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
child: AlertDialog(
|
||||
title: Text(l10n.settings_regionFetchRegions),
|
||||
content: ValueListenableBuilder<(int, int)?>(
|
||||
valueListenable: _fetchProgress,
|
||||
builder: (context, progress, _) => Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 28,
|
||||
height: 28,
|
||||
child: CircularProgressIndicator(strokeWidth: 3),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
progress == null
|
||||
? l10n.settings_regionFetchDiscovering
|
||||
: l10n.settings_regionFetchProgress(
|
||||
progress.$1,
|
||||
progress.$2,
|
||||
),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (!cancel.isCompleted) cancel.complete();
|
||||
progressContext = null;
|
||||
Navigator.pop(dialogContext);
|
||||
},
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
_RegionFetchResult result;
|
||||
try {
|
||||
fetchedRegions = await _fetchRegionsFromRepeaters();
|
||||
result = await _fetchRegionsFromRepeaters(connector, cancel);
|
||||
} finally {
|
||||
if (_fetchCancel == cancel) _fetchCancel = null;
|
||||
// A fetch that fails instantly can finish before the progress dialog
|
||||
// has built; let it build so it can be closed.
|
||||
if (progressContext == null && !cancel.isCompleted) {
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
}
|
||||
final dialog = progressContext;
|
||||
if (dialog != null && dialog.mounted) Navigator.pop(dialog);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isFetchingRegions = false;
|
||||
@@ -299,8 +371,12 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
final l10n = context.l10n;
|
||||
final sortedRegions = fetchedRegions.toList()..sort();
|
||||
if (cancel.isCompleted && result.regions.isEmpty) return;
|
||||
if (!cancel.isCompleted && result.askedRepeaters == 0) {
|
||||
await _showFetchMessage(l10n.settings_regionFetchNoneResponded);
|
||||
return;
|
||||
}
|
||||
final sortedRegions = result.regions.toList()..sort();
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
@@ -345,9 +421,13 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
: null,
|
||||
onPressed: () {
|
||||
if (alreadyExists) {
|
||||
_showDialogSnackBar(
|
||||
context,
|
||||
l10n.settings_regionFetchRegionsAlreadyExists,
|
||||
// Screen context: the root
|
||||
// ScaffoldMessenger, not the dialog's.
|
||||
showDismissibleSnackBar(
|
||||
this.context,
|
||||
content: Text(
|
||||
l10n.settings_regionFetchRegionsAlreadyExists,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -376,54 +456,46 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showDialogSnackBar(BuildContext context, String message) {
|
||||
final overlay = Overlay.maybeOf(context);
|
||||
if (overlay == null) return;
|
||||
|
||||
final theme = Theme.of(context);
|
||||
final entry = OverlayEntry(
|
||||
builder: (context) => Positioned(
|
||||
left: 16,
|
||||
right: 16,
|
||||
bottom: 32,
|
||||
child: SafeArea(
|
||||
child: Material(
|
||||
color: theme.colorScheme.inverseSurface,
|
||||
elevation: 6,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Text(
|
||||
message,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onInverseSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
Future<void> _showFetchMessage(String message) {
|
||||
final l10n = context.l10n;
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.settings_regionFetchRegions),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_close),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
overlay.insert(entry);
|
||||
Timer(const Duration(seconds: 3), entry.remove);
|
||||
}
|
||||
|
||||
Future<Set<Region>> _fetchRegionsFromRepeaters() async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final repeaters = await _discoverNearbyRepeaters(connector);
|
||||
Future<_RegionFetchResult> _fetchRegionsFromRepeaters(
|
||||
MeshCoreConnector connector,
|
||||
Completer<void> cancel,
|
||||
) async {
|
||||
final repeaters = await _discoverNearbyRepeaters(connector, cancel);
|
||||
final regions = <Region>{};
|
||||
var asked = 0;
|
||||
|
||||
for (final repeater in repeaters) {
|
||||
if (!mounted || !connector.isConnected) break;
|
||||
regions.addAll(await _requestRegionsFromRepeater(connector, repeater));
|
||||
if (!mounted || !connector.isConnected || cancel.isCompleted) break;
|
||||
asked++;
|
||||
_fetchProgress.value = (asked, repeaters.length);
|
||||
regions.addAll(
|
||||
await _requestRegionsFromRepeater(connector, repeater, cancel),
|
||||
);
|
||||
}
|
||||
|
||||
return regions;
|
||||
return _RegionFetchResult(regions: regions, askedRepeaters: asked);
|
||||
}
|
||||
|
||||
Future<List<Contact>> _discoverNearbyRepeaters(
|
||||
MeshCoreConnector connector,
|
||||
Completer<void> cancel,
|
||||
) async {
|
||||
final repeaters = connector.contacts
|
||||
.where((contact) => contact.type == advTypeRepeater)
|
||||
@@ -469,9 +541,12 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
}
|
||||
});
|
||||
|
||||
unawaited(cancel.future.then((_) => complete()));
|
||||
|
||||
try {
|
||||
final payload = buildDiscoveryRequestPayload(tag, prefixOnly: true);
|
||||
await connector.sendFrame(buildSendControlDataFrame(payload));
|
||||
if (completer.isCompleted) return <Contact>[];
|
||||
timeout = Timer(const Duration(seconds: 10), complete);
|
||||
final prefixes = await completer.future;
|
||||
return repeaters.where((contact) {
|
||||
@@ -488,6 +563,7 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
Future<Set<Region>> _requestRegionsFromRepeater(
|
||||
MeshCoreConnector connector,
|
||||
Contact repeater,
|
||||
Completer<void> cancel,
|
||||
) async {
|
||||
StreamSubscription<Uint8List>? subscription;
|
||||
Timer? timeout;
|
||||
@@ -509,6 +585,8 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
timeout = Timer(duration, () => complete(<Region>{}));
|
||||
}
|
||||
|
||||
unawaited(cancel.future.then((_) => complete(<Region>{})));
|
||||
|
||||
try {
|
||||
final replyPath = Uint8List(0);
|
||||
const replyHopCount = 0;
|
||||
@@ -561,28 +639,27 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
pathHashWidth: connector.pathHashByteWidth,
|
||||
);
|
||||
await connector.sendFrame(frame);
|
||||
final regions = await completer.future;
|
||||
if (pathChangedForRequest && connector.isConnected) {
|
||||
await _restoreRepeaterPath(
|
||||
connector,
|
||||
repeater,
|
||||
originalPathLength,
|
||||
originalPath,
|
||||
);
|
||||
}
|
||||
return regions;
|
||||
return await completer.future;
|
||||
} catch (_) {
|
||||
timeout?.cancel();
|
||||
subscription?.cancel();
|
||||
if (pathChangedForRequest && connector.isConnected) {
|
||||
await _restoreRepeaterPath(
|
||||
connector,
|
||||
repeater,
|
||||
originalPathLength,
|
||||
originalPath,
|
||||
);
|
||||
}
|
||||
return <Region>{};
|
||||
} finally {
|
||||
timeout?.cancel();
|
||||
await subscription?.cancel();
|
||||
// Always put the user's route back, whatever happened above. (The
|
||||
// connector ignores path writes while disconnected, so nothing can be
|
||||
// restored if the link dropped mid-request.)
|
||||
if (pathChangedForRequest) {
|
||||
try {
|
||||
await _restoreRepeaterPath(
|
||||
connector,
|
||||
repeater,
|
||||
originalPathLength,
|
||||
originalPath,
|
||||
);
|
||||
} catch (_) {
|
||||
// Best effort; the original path is still in the contact store.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,9 +693,11 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
.toSet();
|
||||
}
|
||||
|
||||
void _handleAddRegion(Region region, BuildContext context) {
|
||||
Navigator.pop(context);
|
||||
_regionStore.addRegion(region);
|
||||
void _handleAddRegion(Region region) {
|
||||
// An empty name would collide with the '' "none" dropdown entry.
|
||||
final trimmed = region.trim();
|
||||
if (trimmed.isEmpty) return;
|
||||
_regionStore.addRegion(trimmed);
|
||||
_loadRegions();
|
||||
}
|
||||
|
||||
@@ -686,3 +765,73 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RegionFetchResult {
|
||||
final Set<Region> regions;
|
||||
final int askedRepeaters;
|
||||
|
||||
const _RegionFetchResult({
|
||||
required this.regions,
|
||||
required this.askedRepeaters,
|
||||
});
|
||||
}
|
||||
|
||||
/// Region-name entry. Owns (and disposes) its controller and only enables
|
||||
/// Add once the trimmed name is non-empty; pops with that name.
|
||||
class _AddRegionDialog extends StatefulWidget {
|
||||
const _AddRegionDialog();
|
||||
|
||||
@override
|
||||
State<_AddRegionDialog> createState() => _AddRegionDialogState();
|
||||
}
|
||||
|
||||
class _AddRegionDialogState extends State<_AddRegionDialog> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
final name = _controller.text.trim();
|
||||
if (name.isEmpty) return;
|
||||
Navigator.pop(context, name);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return AlertDialog(
|
||||
title: Text(l10n.settings_regionName),
|
||||
content: TextField(
|
||||
controller: _controller,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.send,
|
||||
onSubmitted: (_) => _submit(),
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.settings_regionNameHint,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.allow(RegExp("[a-z0-9-]")),
|
||||
],
|
||||
maxLength: 30,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
ListenableBuilder(
|
||||
listenable: _controller,
|
||||
builder: (context, _) => TextButton(
|
||||
onPressed: _controller.text.trim().isEmpty ? null : _submit,
|
||||
child: Text(l10n.common_add),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,15 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/confirm_clear_dialog.dart';
|
||||
import '../widgets/debug_frame_viewer.dart';
|
||||
import '../widgets/radio_disconnected_banner.dart';
|
||||
import '../services/repeater_command_service.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
@@ -144,10 +147,12 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
_historyIndex = -1;
|
||||
_commandFocusNode.requestFocus();
|
||||
|
||||
if (showDebug && mounted) {
|
||||
if (showDebug && mounted && _commandService != null) {
|
||||
// Preview the exact framed text the service sends (`XX|` prefix and
|
||||
// clock-sync rewrite), not the bare command.
|
||||
final frame = buildSendCliCommandFrame(
|
||||
widget.repeater.publicKey,
|
||||
command,
|
||||
_commandService!.previewFramedCommand(command),
|
||||
);
|
||||
DebugFrameViewer.showFrameDebug(
|
||||
context,
|
||||
@@ -302,6 +307,50 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _confirmClearHistory() async {
|
||||
final l10n = context.l10n;
|
||||
final confirmed = await showConfirmClearDialog(
|
||||
context,
|
||||
title: l10n.repeater_clearHistory,
|
||||
message: l10n.repeater_cliClearHistoryConfirm,
|
||||
);
|
||||
if (confirmed && mounted) _clearHistory();
|
||||
}
|
||||
|
||||
String _transcriptText() {
|
||||
return _commandHistory
|
||||
.map(
|
||||
(entry) => entry['type'] == 'command'
|
||||
? '> ${entry['text']}'
|
||||
: (entry['text'] ?? ''),
|
||||
)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
Future<void> _copyTranscript() async {
|
||||
if (_commandHistory.isEmpty) return;
|
||||
await Clipboard.setData(ClipboardData(text: _transcriptText()));
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.repeater_cliTranscriptCopied),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _shareTranscript() async {
|
||||
if (_commandHistory.isEmpty) return;
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
text: _transcriptText(),
|
||||
subject: '${context.l10n.repeater_cliTitle} - ${widget.repeater.name}',
|
||||
sharePositionOrigin: box == null
|
||||
? null
|
||||
: box.localToGlobal(Offset.zero) & box.size,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _quickCommandLabel(String key) {
|
||||
final l10n = context.l10n;
|
||||
switch (key) {
|
||||
@@ -335,11 +384,15 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final repeater = _resolveRepeater(connector);
|
||||
final isFloodMode = repeater.pathOverride == -1;
|
||||
final connected = connector.isConnected;
|
||||
final accent = scheme.primary;
|
||||
final hasHistory = _commandHistory.isNotEmpty;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: MeshPalette.bg,
|
||||
backgroundColor: scheme.surfaceContainerLowest,
|
||||
appBar: AppBar(
|
||||
backgroundColor: MeshPalette.bg1,
|
||||
backgroundColor: scheme.surfaceContainer,
|
||||
foregroundColor: scheme.onSurface,
|
||||
title: Text(l10n.repeater_cliTitle),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
@@ -357,25 +410,53 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear_all),
|
||||
tooltip: l10n.repeater_clearHistory,
|
||||
onPressed: _commandHistory.isEmpty ? null : _clearHistory,
|
||||
onPressed: hasHistory ? _confirmClearHistory : null,
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
if (value == 'debug') {
|
||||
if (_commandController.text.trim().isNotEmpty) {
|
||||
_sendCommand(showDebug: true);
|
||||
} else {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_enterCommandFirst),
|
||||
);
|
||||
}
|
||||
switch (value) {
|
||||
case 'debug':
|
||||
if (_commandController.text.trim().isNotEmpty) {
|
||||
_sendCommand(showDebug: true);
|
||||
} else {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_enterCommandFirst),
|
||||
);
|
||||
}
|
||||
case 'copy':
|
||||
_copyTranscript();
|
||||
case 'share':
|
||||
_shareTranscript();
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'copy',
|
||||
enabled: hasHistory,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.copy),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.repeater_cliCopyTranscript),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'share',
|
||||
enabled: hasHistory,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.share),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.repeater_cliShareTranscript),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'debug',
|
||||
enabled: connected,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.bug_report),
|
||||
@@ -390,9 +471,10 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
const RadioDisconnectedBanner(),
|
||||
// Quick commands bar
|
||||
Container(
|
||||
color: MeshPalette.bg1,
|
||||
color: scheme.surfaceContainer,
|
||||
padding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
@@ -405,15 +487,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
label: Text(
|
||||
label,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: MeshPalette.blue,
|
||||
color: accent,
|
||||
),
|
||||
),
|
||||
backgroundColor: MeshPalette.blueBg,
|
||||
side: const BorderSide(color: MeshPalette.blueLine),
|
||||
visualDensity: VisualDensity.compact,
|
||||
onPressed: _regionLoadActive
|
||||
backgroundColor: accent.withValues(alpha: 0.12),
|
||||
side: BorderSide(color: accent.withValues(alpha: 0.5)),
|
||||
onPressed: _regionLoadActive || !connected
|
||||
? null
|
||||
: () => _useQuickCommand(cmd['command']!),
|
||||
),
|
||||
@@ -422,7 +503,7 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
Divider(height: 1, color: MeshPalette.line),
|
||||
Divider(height: 1, color: scheme.outlineVariant),
|
||||
|
||||
// Output area
|
||||
Expanded(
|
||||
@@ -431,11 +512,11 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
: _buildCommandHistory(),
|
||||
),
|
||||
|
||||
Divider(height: 1, color: MeshPalette.line),
|
||||
Divider(height: 1, color: scheme.outlineVariant),
|
||||
|
||||
// Command input
|
||||
Container(
|
||||
color: MeshPalette.bg1,
|
||||
color: scheme.surfaceContainer,
|
||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
||||
child: SafeArea(
|
||||
child: Row(
|
||||
@@ -443,22 +524,20 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.arrow_upward,
|
||||
size: 18,
|
||||
size: 22,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
tooltip: l10n.repeater_previousCommand,
|
||||
onPressed: () => _navigateHistory(true),
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.arrow_downward,
|
||||
size: 18,
|
||||
size: 22,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
tooltip: l10n.repeater_nextCommand,
|
||||
onPressed: () => _navigateHistory(false),
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
@@ -466,73 +545,61 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
controller: _commandController,
|
||||
focusNode: _commandFocusNode,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.ink,
|
||||
fontSize: 15,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: _regionLoadActive
|
||||
? context.l10n.repeater_cliRegionLoadHint
|
||||
: context.l10n.repeater_enterCommandHint,
|
||||
hintStyle: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.ink4,
|
||||
fontSize: 15,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
prefixText: _regionLoadActive ? '' : '> ',
|
||||
prefixStyle: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.blue,
|
||||
fontSize: 15,
|
||||
color: accent,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
filled: true,
|
||||
fillColor: MeshPalette.bg2,
|
||||
fillColor: scheme.surfaceContainerHigh,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 10,
|
||||
vertical: 12,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
borderSide: const BorderSide(
|
||||
color: MeshPalette.line2,
|
||||
),
|
||||
borderSide: BorderSide(color: scheme.outline),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
borderSide: const BorderSide(
|
||||
color: MeshPalette.line2,
|
||||
),
|
||||
borderSide: BorderSide(color: scheme.outline),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
borderSide: const BorderSide(
|
||||
color: MeshPalette.blue,
|
||||
width: 1.5,
|
||||
),
|
||||
borderSide: BorderSide(color: accent, width: 1.5),
|
||||
),
|
||||
),
|
||||
textInputAction: TextInputAction.send,
|
||||
onSubmitted: (_) => _sendCommand(),
|
||||
onSubmitted: (_) {
|
||||
if (connected) _sendCommand();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Material(
|
||||
color: MeshPalette.blue.withValues(alpha: 0.15),
|
||||
shape: const CircleBorder(
|
||||
side: BorderSide(color: MeshPalette.blueLine),
|
||||
),
|
||||
child: InkWell(
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
_sendCommand();
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Icon(
|
||||
Icons.send,
|
||||
size: 18,
|
||||
color: MeshPalette.blue,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 48,
|
||||
height: 48,
|
||||
child: IconButton.filledTonal(
|
||||
tooltip: l10n.repeater_cliSend,
|
||||
icon: const Icon(Icons.send, size: 24),
|
||||
onPressed: connected
|
||||
? () {
|
||||
HapticFeedback.lightImpact();
|
||||
_sendCommand();
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -546,27 +613,38 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.terminal, size: 48, color: MeshPalette.ink4),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.repeater_noCommandsSent,
|
||||
style: MeshTheme.mono(fontSize: 13, color: MeshPalette.ink3),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.repeater_typeCommandOrUseQuick,
|
||||
style: const TextStyle(fontSize: 12, color: MeshPalette.ink4),
|
||||
),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.terminal, size: 48, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.repeater_noCommandsSent,
|
||||
textAlign: TextAlign.center,
|
||||
style: MeshTheme.mono(fontSize: 15, color: scheme.onSurface),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.repeater_typeCommandOrUseQuick,
|
||||
textAlign: TextAlign.center,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommandHistory() {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final accent = scheme.primary;
|
||||
return ListView.builder(
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
@@ -576,7 +654,7 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
final isCommand = entry['type'] == 'command';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 2),
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -586,9 +664,9 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
child: Text(
|
||||
isCommand ? '>' : ' ',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: isCommand ? MeshPalette.blue : MeshPalette.ink3,
|
||||
color: isCommand ? accent : scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -597,8 +675,8 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
child: SelectableText(
|
||||
entry['text']!,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12.5,
|
||||
color: isCommand ? MeshPalette.blue : MeshPalette.ink,
|
||||
fontSize: 14,
|
||||
color: isCommand ? accent : scheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1151,120 +1229,207 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
),
|
||||
];
|
||||
|
||||
showDialog(
|
||||
final sections = <_CommandHelpSection>[
|
||||
_CommandHelpSection(l10n.repeater_general, generalCommands),
|
||||
_CommandHelpSection(l10n.repeater_getCategory, getCommands),
|
||||
_CommandHelpSection(l10n.repeater_settingsCategory, settingsCommands),
|
||||
_CommandHelpSection(l10n.repeater_powerMgmt, powerMgmtCommands),
|
||||
_CommandHelpSection(l10n.repeater_sensors, sensorCommands),
|
||||
_CommandHelpSection(
|
||||
l10n.repeater_bridge,
|
||||
bridgeCommands,
|
||||
note: l10n.repeater_bridgeNote,
|
||||
),
|
||||
_CommandHelpSection(l10n.repeater_logging, loggingCommands),
|
||||
_CommandHelpSection(
|
||||
l10n.repeater_neighborsRepeaterOnly,
|
||||
neighborCommands,
|
||||
),
|
||||
_CommandHelpSection(
|
||||
l10n.repeater_regionManagementRepeaterOnly,
|
||||
regionCommands,
|
||||
note: l10n.repeater_regionNote,
|
||||
),
|
||||
_CommandHelpSection(
|
||||
l10n.repeater_gpsManagement,
|
||||
gpsCommands,
|
||||
note: l10n.repeater_gpsNote,
|
||||
),
|
||||
];
|
||||
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(l10n.repeater_commandsListTitle),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.repeater_commandsListNote,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
showDragHandle: true,
|
||||
builder: (sheetContext) =>
|
||||
_CommandHelpSheet(sections: sections, onSelect: _applyHelpCommand),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CommandHelpSection {
|
||||
final String title;
|
||||
final List<_CommandHelpEntry> commands;
|
||||
final String? note;
|
||||
const _CommandHelpSection(this.title, this.commands, {this.note});
|
||||
}
|
||||
|
||||
/// Searchable, lazily built list of CLI commands.
|
||||
class _CommandHelpSheet extends StatefulWidget {
|
||||
final List<_CommandHelpSection> sections;
|
||||
final ValueChanged<String> onSelect;
|
||||
|
||||
const _CommandHelpSheet({required this.sections, required this.onSelect});
|
||||
|
||||
@override
|
||||
State<_CommandHelpSheet> createState() => _CommandHelpSheetState();
|
||||
}
|
||||
|
||||
class _CommandHelpSheetState extends State<_CommandHelpSheet> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
String _query = '';
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Section headers ([_CommandHelpSection]) interleaved with their matching
|
||||
/// [_CommandHelpEntry] rows.
|
||||
List<Object> _rows() {
|
||||
final q = _query.trim().toLowerCase();
|
||||
final rows = <Object>[];
|
||||
for (final section in widget.sections) {
|
||||
final matches = q.isEmpty
|
||||
? section.commands
|
||||
: section.commands
|
||||
.where(
|
||||
(e) =>
|
||||
e.command.toLowerCase().contains(q) ||
|
||||
e.description.toLowerCase().contains(q),
|
||||
)
|
||||
.toList();
|
||||
if (matches.isEmpty) continue;
|
||||
rows.add(section);
|
||||
rows.addAll(matches);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final rows = _rows();
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
|
||||
child: DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.85,
|
||||
minChildSize: 0.4,
|
||||
maxChildSize: 1,
|
||||
builder: (context, scrollController) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.repeater_commandsListTitle,
|
||||
style: textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.repeater_commandsListNote,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
hintText: l10n.repeater_cliSearchCommands,
|
||||
suffixIcon: _query.isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
tooltip: l10n.common_clearSearch,
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
setState(() => _query = '');
|
||||
},
|
||||
),
|
||||
),
|
||||
onChanged: (value) => setState(() => _query = value),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_general,
|
||||
generalCommands,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_getCategory,
|
||||
getCommands,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_settingsCategory,
|
||||
settingsCommands,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_powerMgmt,
|
||||
powerMgmtCommands,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(context, l10n.repeater_sensors, sensorCommands),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_bridge,
|
||||
bridgeCommands,
|
||||
note: l10n.repeater_bridgeNote,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_logging,
|
||||
loggingCommands,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_neighborsRepeaterOnly,
|
||||
neighborCommands,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_regionManagementRepeaterOnly,
|
||||
regionCommands,
|
||||
note: l10n.repeater_regionNote,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_gpsManagement,
|
||||
gpsCommands,
|
||||
note: l10n.repeater_gpsNote,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: rows.isEmpty
|
||||
? Center(
|
||||
child: Text(
|
||||
l10n.repeater_cliNoMatchingCommands,
|
||||
style: textTheme.bodyLarge?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
itemCount: rows.length,
|
||||
itemBuilder: (context, index) {
|
||||
final row = rows[index];
|
||||
if (row is _CommandHelpSection) {
|
||||
return _buildHeader(row, isFirst: index == 0);
|
||||
}
|
||||
return _buildCommandCard(row as _CommandHelpEntry);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.common_close),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(_CommandHelpSection section, {required bool isFirst}) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: isFirst ? 4 : 16, bottom: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
section.title,
|
||||
style: textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (section.note != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
section.note!,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHelpSection(
|
||||
BuildContext context,
|
||||
String title,
|
||||
List<_CommandHelpEntry> commands, {
|
||||
String? note,
|
||||
}) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
|
||||
),
|
||||
if (note != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
note,
|
||||
style: TextStyle(fontSize: 11, color: scheme.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
...commands.map((entry) => _buildHelpCommandCard(context, entry)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHelpCommandCard(BuildContext context, _CommandHelpEntry entry) {
|
||||
Widget _buildCommandCard(_CommandHelpEntry entry) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
return Card(
|
||||
elevation: 0,
|
||||
margin: const EdgeInsets.only(bottom: 6),
|
||||
@@ -1275,24 +1440,26 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.sm),
|
||||
onTap: () => _applyHelpCommand(entry.command),
|
||||
onTap: () => widget.onSelect(entry.command),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
entry.command,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: MeshPalette.blue,
|
||||
color: scheme.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
entry.description,
|
||||
style: TextStyle(fontSize: 12, color: scheme.onSurfaceVariant),
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../l10n/contact_localization.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/radio_disconnected_banner.dart';
|
||||
import 'repeater_status_screen.dart';
|
||||
import 'repeater_cli_screen.dart';
|
||||
import 'repeater_settings_screen.dart';
|
||||
@@ -51,6 +52,7 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
const RadioDisconnectedBanner(),
|
||||
// ── Identity card ─────────────────────────────────────────────
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 20, 16, 4),
|
||||
@@ -81,7 +83,7 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
Text(
|
||||
repeater.shortPubKeyHex,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
@@ -100,7 +102,7 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
children: [
|
||||
Icon(
|
||||
Icons.location_on,
|
||||
size: 12,
|
||||
size: 16,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 3),
|
||||
@@ -109,7 +111,7 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
'${repeater.latitude?.toStringAsFixed(4)}, '
|
||||
'${repeater.longitude?.toStringAsFixed(4)}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10,
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -308,6 +310,7 @@ class _HubActionTile extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
return ListEntrance(
|
||||
index: index,
|
||||
child: Semantics(
|
||||
@@ -334,16 +337,14 @@ class _HubActionTile extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
style: textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../services/repeater_command_service.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/radio_disconnected_banner.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
import '../utils/keys.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
@@ -204,6 +205,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
static const int _maxNameBytes = 31;
|
||||
static const int _maxOwnerInfoBytes = 119;
|
||||
static const int _maxAgcResetInterval = 255 * 4;
|
||||
// PRV_KEY_SIZE is 64 bytes (expanded Ed25519 key), i.e. 128 hex chars;
|
||||
// firmware `set prv.key` rejects anything else.
|
||||
static const int _prvKeyHexLength = 128;
|
||||
static final RegExp _prvKeyPattern = RegExp(r'^[0-9a-fA-F]{128}$');
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -212,6 +217,24 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
_commandService = RepeaterCommandService(connector);
|
||||
_setupMessageListener();
|
||||
_loadSettings();
|
||||
// Fetch current values on open instead of showing disabled fields.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
if (connector.isConnected) _refreshAll();
|
||||
});
|
||||
}
|
||||
|
||||
/// Returns true when the radio is connected; otherwise tells the user.
|
||||
bool _ensureConnected() {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
if (connector.isConnected) return true;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.repeater_radioDisconnected),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -474,6 +497,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
required ValueSetter<bool> setRefreshing,
|
||||
}) async {
|
||||
if (_commandService == null) return;
|
||||
if (!_loadingAll && !_ensureConnected()) return;
|
||||
final l10n = context.l10n;
|
||||
|
||||
setState(() => setRefreshing(true));
|
||||
@@ -702,8 +726,16 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
|
||||
/// Send a one-shot CLI action (advert / clock sync / etc.) and surface the
|
||||
/// firmware's reply via snackbar. Not part of the dirty-field save flow.
|
||||
Future<void> _runAction(String command, String label) async {
|
||||
///
|
||||
/// With [replyOptional] (e.g. `reboot`, which restarts without answering) a
|
||||
/// timeout means the command went out; it is reported as sent, not failed.
|
||||
Future<void> _runAction(
|
||||
String command,
|
||||
String label, {
|
||||
bool replyOptional = false,
|
||||
}) async {
|
||||
if (_commandService == null) return;
|
||||
if (!_ensureConnected()) return;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final repeater = _resolveRepeater(connector);
|
||||
final l10n = context.l10n;
|
||||
@@ -729,6 +761,13 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
if (replyOptional && e.toString().contains('Command timeout')) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_actionSentNoReply(label)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_actionFailed(label, e.toString())),
|
||||
@@ -741,6 +780,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
|
||||
Future<void> _refreshAll() async {
|
||||
if (_loadingAll) return;
|
||||
if (!_ensureConnected()) return;
|
||||
final sections = <Future<void> Function()>[
|
||||
_refreshBasicSettings,
|
||||
_refreshRadioSettings,
|
||||
@@ -883,10 +923,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
);
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.name) &&
|
||||
_nameController.text.isNotEmpty) {
|
||||
_nameController.text.trim().isNotEmpty) {
|
||||
pending.add((
|
||||
field: _SettingField.name,
|
||||
command: 'set name ${_nameController.text}',
|
||||
command: 'set name ${_nameController.text.trim()}',
|
||||
));
|
||||
}
|
||||
|
||||
@@ -916,16 +956,28 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
if (freq == null || freq < 150 || freq > 2500) {
|
||||
reject(_SettingField.radio, l10n.repeater_frequencyInvalid);
|
||||
} else if (bwKHz < 7.8 || bwKHz > 500) {
|
||||
reject(_SettingField.radio, '${l10n.repeater_bandwidth}: $bwKHz');
|
||||
reject(
|
||||
_SettingField.radio,
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_bandwidth,
|
||||
'$bwKHz',
|
||||
),
|
||||
);
|
||||
} else if (_spreadingFactor! < 5 || _spreadingFactor! > 12) {
|
||||
reject(
|
||||
_SettingField.radio,
|
||||
'${l10n.repeater_spreadingFactor}: $_spreadingFactor',
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_spreadingFactor,
|
||||
'$_spreadingFactor',
|
||||
),
|
||||
);
|
||||
} else if (_codingRate! < 5 || _codingRate! > 8) {
|
||||
reject(
|
||||
_SettingField.radio,
|
||||
'${l10n.repeater_codingRate}: $_codingRate',
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_codingRate,
|
||||
'$_codingRate',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
pending.add((
|
||||
@@ -944,8 +996,11 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
dbm > _maxRepeaterTxPower) {
|
||||
reject(
|
||||
_SettingField.txPower,
|
||||
'${l10n.repeater_txPower}: ${_txPowerController.text.trim()} '
|
||||
'($_minRepeaterTxPower-$_maxRepeaterTxPower dBm)',
|
||||
l10n.repeater_txPowerOutOfRange(
|
||||
_txPowerController.text.trim(),
|
||||
_minRepeaterTxPower,
|
||||
_maxRepeaterTxPower,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
pending.add((field: _SettingField.txPower, command: 'set tx $dbm'));
|
||||
@@ -962,7 +1017,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.lat,
|
||||
'${l10n.repeater_latitude}: ${_latController.text.trim()}',
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_latitude,
|
||||
_latController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -976,7 +1034,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.lon,
|
||||
'${l10n.repeater_longitude}: ${_lonController.text.trim()}',
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_longitude,
|
||||
_lonController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1053,8 +1114,13 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.prvKey)) {
|
||||
final v = _prvKeyController.text.trim();
|
||||
if (v != "") {
|
||||
if (_prvKeyPattern.hasMatch(v)) {
|
||||
pending.add((field: _SettingField.prvKey, command: 'set prv.key $v'));
|
||||
} else if (v.isNotEmpty) {
|
||||
reject(
|
||||
_SettingField.prvKey,
|
||||
l10n.repeater_prvKeyLengthError(_prvKeyHexLength),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.txDelay) &&
|
||||
@@ -1068,7 +1134,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.txDelay,
|
||||
'${l10n.repeater_txDelay}: ${_txDelayController.text.trim()}',
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_txDelay,
|
||||
_txDelayController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1085,8 +1154,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.directTxDelay,
|
||||
'${l10n.repeater_directTxDelay}: '
|
||||
'${_directTxDelayController.text.trim()}',
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_directTxDelay,
|
||||
_directTxDelayController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1101,7 +1172,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.intThresh,
|
||||
'${l10n.repeater_intThresh}: ${_intThreshController.text.trim()}',
|
||||
l10n.repeater_invalidSettingValue(
|
||||
l10n.repeater_intThresh,
|
||||
_intThreshController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1244,6 +1318,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
prefix,
|
||||
_searchChunkTime,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (keys == null) {
|
||||
// Ran out of time; schedule another attempt.
|
||||
Timer.run(_searchForKeyPair);
|
||||
@@ -1283,83 +1358,139 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final repeater = _resolveRepeater(connector);
|
||||
final isFloodMode = repeater.pathOverride == -1;
|
||||
final connected = connector.isConnected;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(l10n.repeater_settingsTitle),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
||||
tooltip: l10n.repeater_routingMode,
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: repeater),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: l10n.repeater_refreshAll,
|
||||
onPressed: _loadingAll || _isLoading ? null : _refreshAll,
|
||||
),
|
||||
if (_hasChanges)
|
||||
TextButton.icon(
|
||||
onPressed: _isLoading || _loadingAll ? null : _saveSettings,
|
||||
icon: const Icon(Icons.save),
|
||||
label: Text(l10n.common_save),
|
||||
return PopScope(
|
||||
canPop: !_hasChanges,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop) _confirmDiscardChanges();
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(l10n.repeater_settingsTitle),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
||||
tooltip: l10n.repeater_routingMode,
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: repeater),
|
||||
),
|
||||
],
|
||||
bottom: _loadingAll
|
||||
? PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: LinearProgressIndicator(value: _loadAllProgress),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: _isLoading && _nameController.text.isEmpty
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
if (_loadedKeys.isEmpty && !_loadingAll)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: MeshCard(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.repeater_settingsNotLoaded,
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: l10n.repeater_refreshAll,
|
||||
onPressed: _loadingAll || _isLoading || !connected
|
||||
? null
|
||||
: _refreshAll,
|
||||
),
|
||||
if (_hasChanges)
|
||||
TextButton.icon(
|
||||
onPressed: _isLoading || _loadingAll || !connected
|
||||
? null
|
||||
: _saveSettings,
|
||||
icon: const Icon(Icons.save),
|
||||
label: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
bottom: _loadingAll
|
||||
? PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: LinearProgressIndicator(value: _loadAllProgress),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: _isLoading && _nameController.text.isEmpty
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
const RadioDisconnectedBanner(),
|
||||
if (_loadedKeys.isEmpty && !_loadingAll)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: MeshCard(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.repeater_settingsNotLoaded,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isLoading ? null : _refreshAll,
|
||||
child: Text(context.l10n.repeater_refreshAll),
|
||||
),
|
||||
],
|
||||
TextButton(
|
||||
onPressed: _isLoading || !connected
|
||||
? null
|
||||
: _refreshAll,
|
||||
child: Text(context.l10n.repeater_refreshAll),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBasicSettingsCard(),
|
||||
_buildRadioSettingsCard(),
|
||||
_buildLocationSettingsCard(),
|
||||
_buildFeatureTogglesCard(),
|
||||
_buildNetworkHealthCard(),
|
||||
_buildAdvertisementSettingsCard(),
|
||||
_buildOwnerInfoCard(),
|
||||
_buildActionsCard(),
|
||||
_buildAdvancedCard(),
|
||||
_buildKeysCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildDangerZoneCard(),
|
||||
],
|
||||
),
|
||||
_buildBasicSettingsCard(),
|
||||
_buildRadioSettingsCard(),
|
||||
_buildLocationSettingsCard(),
|
||||
_buildFeatureTogglesCard(),
|
||||
_buildNetworkHealthCard(),
|
||||
_buildAdvertisementSettingsCard(),
|
||||
_buildOwnerInfoCard(),
|
||||
_buildActionsCard(),
|
||||
_buildAdvancedCard(),
|
||||
_buildKeysCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildDangerZoneCard(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _confirmDiscardChanges() async {
|
||||
final l10n = context.l10n;
|
||||
final choice = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
final canSave =
|
||||
!_isLoading &&
|
||||
!_loadingAll &&
|
||||
dialogContext.read<MeshCoreConnector>().isConnected;
|
||||
return AlertDialog(
|
||||
title: Text(l10n.repeater_unsavedChangesTitle),
|
||||
content: Text(l10n.repeater_unsavedChangesMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, 'discard'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(dialogContext).colorScheme.error,
|
||||
),
|
||||
child: Text(l10n.repeater_discardChanges),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: canSave
|
||||
? () => Navigator.pop(dialogContext, 'save')
|
||||
: null,
|
||||
child: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
if (!mounted || choice == null) return;
|
||||
if (choice == 'save') {
|
||||
await _saveSettings();
|
||||
if (!mounted || _hasChanges) return;
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
Widget _buildBasicSettingsCard() {
|
||||
final l10n = context.l10n;
|
||||
final refreshButton = _refreshingBasic
|
||||
@@ -1824,10 +1955,14 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _advertInterval.clamp(60, 240).toDouble(),
|
||||
min: 60,
|
||||
max: 240,
|
||||
divisions: 18,
|
||||
// Widen the range to include an out-of-range firmware value
|
||||
// so the knob matches the subtitle.
|
||||
value: _advertSliderValue.toDouble(),
|
||||
min: _advertSliderMin.toDouble(),
|
||||
max: _advertSliderMax.toDouble(),
|
||||
divisions: (_advertSliderMax - _advertSliderMin) % 10 == 0
|
||||
? (_advertSliderMax - _advertSliderMin) ~/ 10
|
||||
: null,
|
||||
label: l10n.repeater_localAdvertIntervalMinutes(
|
||||
_advertInterval,
|
||||
),
|
||||
@@ -1887,10 +2022,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _floodAdvertInterval.clamp(3, 168).toDouble(),
|
||||
min: 3,
|
||||
max: 168,
|
||||
divisions: 165,
|
||||
value: _floodAdvertSliderValue.toDouble(),
|
||||
min: _floodAdvertSliderMin.toDouble(),
|
||||
max: _floodAdvertSliderMax.toDouble(),
|
||||
divisions: _floodAdvertSliderMax - _floodAdvertSliderMin,
|
||||
label: l10n.repeater_floodAdvertIntervalHours(
|
||||
_floodAdvertInterval,
|
||||
),
|
||||
@@ -1952,6 +2087,23 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// Slider bounds: the normal UI range, widened to include a non-zero value
|
||||
// the firmware reported outside it. A disabled (0) value parks the knob at
|
||||
// the minimum.
|
||||
int get _advertSliderMin =>
|
||||
_advertInterval > 0 && _advertInterval < 60 ? _advertInterval : 60;
|
||||
int get _advertSliderMax => _advertInterval > 240 ? _advertInterval : 240;
|
||||
int get _advertSliderValue =>
|
||||
_advertInterval.clamp(_advertSliderMin, _advertSliderMax);
|
||||
int get _floodAdvertSliderMin =>
|
||||
_floodAdvertInterval > 0 && _floodAdvertInterval < 3
|
||||
? _floodAdvertInterval
|
||||
: 3;
|
||||
int get _floodAdvertSliderMax =>
|
||||
_floodAdvertInterval > 168 ? _floodAdvertInterval : 168;
|
||||
int get _floodAdvertSliderValue =>
|
||||
_floodAdvertInterval.clamp(_floodAdvertSliderMin, _floodAdvertSliderMax);
|
||||
|
||||
Widget _buildNetworkHealthCard() {
|
||||
final l10n = context.l10n;
|
||||
return Column(
|
||||
@@ -2100,6 +2252,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
|
||||
Widget _buildActionsCard() {
|
||||
final l10n = context.l10n;
|
||||
final canAct =
|
||||
!_runningAction && context.watch<MeshCoreConnector>().isConnected;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -2112,8 +2266,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
leading: const Icon(Icons.podcasts),
|
||||
title: Text(l10n.repeater_sendAdvert),
|
||||
subtitle: Text(l10n.repeater_sendAdvertSubtitle),
|
||||
enabled: !_runningAction,
|
||||
onTap: _runningAction
|
||||
enabled: canAct,
|
||||
onTap: !canAct
|
||||
? null
|
||||
: () => _runAction('advert', l10n.repeater_sendAdvert),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -2122,8 +2276,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
leading: const Icon(Icons.cell_tower),
|
||||
title: Text(l10n.repeater_sendAdvertZeroHop),
|
||||
subtitle: Text(l10n.repeater_sendAdvertZeroHopSubtitle),
|
||||
enabled: !_runningAction,
|
||||
onTap: _runningAction
|
||||
enabled: canAct,
|
||||
onTap: !canAct
|
||||
? null
|
||||
: () => _runAction(
|
||||
'advert.zerohop',
|
||||
@@ -2135,8 +2289,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
leading: const Icon(Icons.access_time),
|
||||
title: Text(l10n.repeater_clockSync),
|
||||
subtitle: Text(l10n.repeater_clockSyncSubtitle),
|
||||
enabled: !_runningAction,
|
||||
onTap: _runningAction
|
||||
enabled: canAct,
|
||||
onTap: !canAct
|
||||
? null
|
||||
: () => _runAction('clock sync', l10n.repeater_clockSync),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -2351,6 +2505,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _prvKeyController,
|
||||
maxLength: _prvKeyHexLength,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp("[0-9a-fA-F]")),
|
||||
],
|
||||
@@ -2358,6 +2513,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
labelText: l10n.repeater_prvKey,
|
||||
helperText: l10n.repeater_prvKeyHelper,
|
||||
helperMaxLines: 3,
|
||||
errorText:
|
||||
_prvKeyController.text.isNotEmpty &&
|
||||
!_prvKeyPattern.hasMatch(_prvKeyController.text)
|
||||
? l10n.repeater_prvKeyLengthError(_prvKeyHexLength)
|
||||
: null,
|
||||
errorMaxLines: 3,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
onChanged: (_) {
|
||||
@@ -2365,6 +2526,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
if (_prvKeyController.text.isNotEmpty) {
|
||||
_markChanged(_SettingField.prvKey);
|
||||
}
|
||||
// Refresh the inline length error.
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -2456,6 +2619,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
|
||||
Widget _buildDangerZoneCard() {
|
||||
final l10n = context.l10n;
|
||||
final canAct =
|
||||
!_runningAction && context.watch<MeshCoreConnector>().isConnected;
|
||||
return MeshCard(
|
||||
color: MeshPalette.alertBg,
|
||||
borderColor: MeshPalette.alertLine,
|
||||
@@ -2488,29 +2653,28 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
l10n.repeater_rebootRepeaterSubtitle,
|
||||
style: const TextStyle(color: MeshPalette.warnDim),
|
||||
),
|
||||
enabled: canAct,
|
||||
onTap: () => _confirmAction(
|
||||
l10n.repeater_rebootRepeater,
|
||||
l10n.repeater_rebootRepeaterConfirm,
|
||||
() => _sendDangerCommand('reboot'),
|
||||
() => _runAction(
|
||||
'reboot',
|
||||
l10n.repeater_rebootRepeater,
|
||||
replyOptional: true,
|
||||
),
|
||||
isDestructive: true,
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
// Regenerate identity key - hidden until fully implemented
|
||||
// Erase is serial-console only in firmware; shown disabled with
|
||||
// an explanation rather than behind a confirm that does nothing.
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete_forever, color: MeshPalette.alert),
|
||||
title: Text(
|
||||
l10n.repeater_eraseFileSystem,
|
||||
style: const TextStyle(color: MeshPalette.alert),
|
||||
),
|
||||
enabled: false,
|
||||
leading: const Icon(Icons.delete_forever),
|
||||
title: Text(l10n.repeater_eraseFileSystem),
|
||||
subtitle: Text(
|
||||
l10n.repeater_eraseFileSystemSubtitle,
|
||||
style: const TextStyle(color: MeshPalette.warnDim),
|
||||
),
|
||||
onTap: () => _confirmAction(
|
||||
l10n.repeater_eraseFileSystem,
|
||||
l10n.repeater_eraseFileSystemConfirm,
|
||||
() => _sendDangerCommand('erase'),
|
||||
isDestructive: true,
|
||||
'${l10n.repeater_eraseFileSystemSubtitle}\n'
|
||||
'${l10n.repeater_eraseSerialOnly}',
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -2519,54 +2683,6 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _sendDangerCommand(String command) async {
|
||||
final l10n = context.l10n;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final repeater = _resolveRepeater(connector);
|
||||
|
||||
if (command == 'erase') {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_eraseSerialOnly),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final selection = await connector.preparePathForContactSend(repeater);
|
||||
final timestampSeconds = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
connector.trackRepeaterAck(
|
||||
contact: repeater,
|
||||
selection: selection,
|
||||
text: command,
|
||||
timestampSeconds: timestampSeconds,
|
||||
);
|
||||
final frame = buildSendCliCommandFrame(
|
||||
repeater.publicKey,
|
||||
command,
|
||||
timestampSeconds: timestampSeconds,
|
||||
);
|
||||
await connector.sendFrame(frame);
|
||||
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_commandSent(command)),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_errorSendingCommand(e.toString())),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _confirmAction(
|
||||
String title,
|
||||
String message,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
@@ -14,8 +15,8 @@ import '../services/repeater_command_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/battery_utils.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/radio_disconnected_banner.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
|
||||
class RepeaterStatusScreen extends StatefulWidget {
|
||||
final Contact repeater;
|
||||
@@ -60,6 +61,7 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
int? _dupDirect;
|
||||
double? _chanUtil;
|
||||
PathSelection? _pendingStatusSelection;
|
||||
String? _loadError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -116,7 +118,16 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
if (parsed == null) return;
|
||||
if (!_matchesRepeaterPrefix(parsed.senderPrefix)) return;
|
||||
_commandService?.handleResponse(widget.repeater, parsed.text);
|
||||
_parseStatusResponse(parsed.text);
|
||||
// Only a reply that actually carried status fields ends the request;
|
||||
// any other text from this repeater (e.g. a CLI reply) is ignored here.
|
||||
if (!_parseStatusResponse(parsed.text)) return;
|
||||
_statusTimeout?.cancel();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_loadError = null;
|
||||
});
|
||||
}
|
||||
_recordStatusResult(true);
|
||||
}
|
||||
|
||||
@@ -132,6 +143,7 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
final rxAirSecs = stats.rxAirSecs;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_loadError = null;
|
||||
_batteryMv = stats.batteryMv;
|
||||
_queueLen = stats.queueLen;
|
||||
_noiseFloor = stats.noiseFloor;
|
||||
@@ -177,8 +189,10 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
return true;
|
||||
}
|
||||
|
||||
void _parseStatusResponse(String response) {
|
||||
/// Applies a JSON status reply. Returns true if any status field was set.
|
||||
bool _parseStatusResponse(String response) {
|
||||
final trimmed = response.trim();
|
||||
var applied = false;
|
||||
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
||||
try {
|
||||
final data = jsonDecode(trimmed) as Map<String, dynamic>;
|
||||
@@ -187,6 +201,7 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_uptimeSecs = _asInt(data['uptime_secs']);
|
||||
_queueLen = _asInt(data['queue_len']);
|
||||
_debugFlags = _asInt(data['errors']);
|
||||
applied = true;
|
||||
final batteryMv = _batteryMv;
|
||||
if (batteryMv != null) {
|
||||
final connector = Provider.of<MeshCoreConnector>(
|
||||
@@ -205,6 +220,7 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_lastSnr = _asDouble(data['last_snr']);
|
||||
_txAirSecs = _asInt(data['tx_air_secs']);
|
||||
_rxAirSecs = _asInt(data['rx_air_secs']);
|
||||
applied = true;
|
||||
} else if (data.containsKey('recv') || data.containsKey('sent')) {
|
||||
_packetsRecv = _asInt(data['recv']);
|
||||
_packetsSent = _asInt(data['sent']);
|
||||
@@ -214,17 +230,30 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_directRx = _asInt(data['direct_rx']);
|
||||
_dupFlood = _asInt(data['dup_flood']);
|
||||
_dupDirect = _asInt(data['dup_direct']);
|
||||
applied = true;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
if (mounted) setState(() {});
|
||||
if (applied && mounted) setState(() {});
|
||||
return applied;
|
||||
}
|
||||
|
||||
bool get _hasAnyStatus =>
|
||||
_batteryMv != null ||
|
||||
_uptimeSecs != null ||
|
||||
_queueLen != null ||
|
||||
_lastRssi != null ||
|
||||
_noiseFloor != null ||
|
||||
_txAirSecs != null ||
|
||||
_packetsSent != null ||
|
||||
_packetsRecv != null;
|
||||
|
||||
Future<void> _loadStatus() async {
|
||||
if (_commandService == null) return;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_loadError = null;
|
||||
_pendingStatusSelection = null;
|
||||
_batteryMv = null;
|
||||
_uptimeSecs = null;
|
||||
@@ -269,22 +298,18 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_statusTimeout?.cancel();
|
||||
_statusTimeout = Timer(Duration(milliseconds: timeoutMs), () {
|
||||
if (!mounted) return;
|
||||
setState(() => _isLoading = false);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.repeater_statusRequestTimeout),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_loadError = context.l10n.repeater_statusRequestTimeout;
|
||||
});
|
||||
_recordStatusResult(false);
|
||||
});
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() => _isLoading = false);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.repeater_errorLoadingStatus(e.toString())),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_loadError = context.l10n.repeater_errorLoadingStatus(e.toString());
|
||||
});
|
||||
}
|
||||
_recordStatusResult(false);
|
||||
}
|
||||
@@ -338,11 +363,8 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final dt = connector.repeaterClockAtLogin(widget.repeater.publicKey);
|
||||
if (dt == null) return '—';
|
||||
final local = dt.toLocal();
|
||||
final date = '${local.day}/${local.month}/${local.year}';
|
||||
final time =
|
||||
'${local.hour.toString().padLeft(2, '0')}:${local.minute.toString().padLeft(2, '0')}';
|
||||
return '$date $time';
|
||||
final locale = Localizations.localeOf(context).toLanguageTag();
|
||||
return DateFormat.yMd(locale).add_Hm().format(dt.toLocal());
|
||||
}
|
||||
|
||||
String _formatDuration(int? seconds) {
|
||||
@@ -412,6 +434,7 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final repeater = _resolveRepeater(connector);
|
||||
final isFloodMode = repeater.pathOverride == -1;
|
||||
final canRefresh = !_isLoading && connector.isConnected;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -432,18 +455,25 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.refresh),
|
||||
onPressed: _isLoading ? null : _loadStatus,
|
||||
onPressed: canRefresh ? _loadStatus : null,
|
||||
tooltip: l10n.repeater_refresh,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: RefreshIndicator(
|
||||
onRefresh: _loadStatus,
|
||||
child: _isLoading && _batteryMv == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _buildBody(l10n, repeater.name),
|
||||
child: Column(
|
||||
children: [
|
||||
const RadioDisconnectedBanner(),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: connector.isConnected ? _loadStatus : () async {},
|
||||
child: _isLoading && !_hasAnyStatus
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _buildBody(l10n, repeater.name),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -451,9 +481,21 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
|
||||
Widget _buildBody(dynamic l10n, String name) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final error = _loadError;
|
||||
if (error != null && !_hasAnyStatus) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(top: 16, bottom: 24),
|
||||
children: [_buildErrorCard(error)],
|
||||
);
|
||||
}
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
if (error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: _buildErrorCard(error),
|
||||
),
|
||||
// ── System ─────────────────────────────────────────────────────────
|
||||
SectionHeader(l10n.repeater_systemInformation),
|
||||
Padding(
|
||||
@@ -502,7 +544,7 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_StatItem(
|
||||
icon: Icons.signal_cellular_alt,
|
||||
label: l10n.repeater_lastRssi,
|
||||
value: _formatValue(_lastRssi, suffix: ' dB'),
|
||||
value: _formatValue(_lastRssi, suffix: ' dBm'),
|
||||
color: MeshPalette.blue,
|
||||
),
|
||||
_StatItem(
|
||||
@@ -514,7 +556,7 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_StatItem(
|
||||
icon: Icons.noise_control_off,
|
||||
label: l10n.repeater_noiseFloor,
|
||||
value: _formatValue(_noiseFloor, suffix: ' dB'),
|
||||
value: _formatValue(_noiseFloor, suffix: ' dBm'),
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
_StatItem(
|
||||
@@ -596,6 +638,49 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorCard(String message) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final connected = context.watch<MeshCoreConnector>().isConnected;
|
||||
return MeshCard(
|
||||
color: scheme.errorContainer,
|
||||
borderColor: scheme.error,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 24,
|
||||
color: scheme.onErrorContainer,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
message,
|
||||
style: textTheme.bodyLarge?.copyWith(
|
||||
color: scheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: FilledButton.icon(
|
||||
onPressed: _isLoading || !connected ? null : _loadStatus,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: Text(context.l10n.common_retry),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _batteryColor() {
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final batteryMv =
|
||||
|
||||
@@ -42,6 +42,8 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
_connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
|
||||
_connectionListener = () {
|
||||
// ModalRoute.of needs a live element, so bail out before touching it.
|
||||
if (!mounted) return;
|
||||
final isCurrentRoute = ModalRoute.of(context)?.isCurrent ?? true;
|
||||
if (_connector.state == MeshCoreConnectionState.disconnected) {
|
||||
_changedNavigation = false;
|
||||
@@ -53,11 +55,9 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
isCurrentRoute &&
|
||||
!_changedNavigation) {
|
||||
_changedNavigation = true;
|
||||
if (mounted) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const ChannelsScreen()),
|
||||
);
|
||||
}
|
||||
Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute(builder: (context) => const ChannelsScreen()));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -448,16 +448,13 @@ class _BluetoothOffBanner extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
color: scheme.error,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13.5,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
context.l10n.scanner_bluetoothOffMessage,
|
||||
style: TextStyle(
|
||||
color: scheme.error.withValues(alpha: 0.8),
|
||||
fontSize: 12,
|
||||
),
|
||||
style: TextStyle(color: scheme.error, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
+629
-1204
File diff suppressed because it is too large.
Load diff
+33
-10
@@ -28,6 +28,8 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
late final MeshCoreConnector _connector;
|
||||
late final VoidCallback _connectionListener;
|
||||
bool _navigatedToChannels = false;
|
||||
String? _hostError;
|
||||
String? _portError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -47,8 +49,12 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
if (_connector.state == MeshCoreConnectionState.disconnected) {
|
||||
_navigatedToChannels = false;
|
||||
}
|
||||
// Only navigate while this route is on top; otherwise a reconnect
|
||||
// would replace whatever screen the user has pushed above it.
|
||||
final isCurrentRoute = ModalRoute.of(context)?.isCurrent ?? true;
|
||||
if (_connector.state == MeshCoreConnectionState.connected &&
|
||||
_connector.isTcpTransportConnected &&
|
||||
isCurrentRoute &&
|
||||
!_navigatedToChannels) {
|
||||
context.read<AppSettingsService>().setTcpServerAddress(
|
||||
_hostController.text,
|
||||
@@ -122,7 +128,7 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
_buildTransportLinks(context),
|
||||
|
||||
// Connection form
|
||||
const SectionHeader('TCP / IP'),
|
||||
SectionHeader(context.l10n.tcpSectionTitle),
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -133,9 +139,16 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.tcpHostLabel,
|
||||
hintText: context.l10n.tcpHostHint,
|
||||
errorText: _hostError,
|
||||
errorMaxLines: 3,
|
||||
),
|
||||
enabled: !isConnecting,
|
||||
keyboardType: TextInputType.url,
|
||||
onChanged: (_) {
|
||||
if (_hostError != null) {
|
||||
setState(() => _hostError = null);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
@@ -143,9 +156,16 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.tcpPortLabel,
|
||||
hintText: context.l10n.tcpPortHint,
|
||||
errorText: _portError,
|
||||
errorMaxLines: 3,
|
||||
),
|
||||
enabled: !isConnecting,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (_) {
|
||||
if (_portError != null) {
|
||||
setState(() => _portError = null);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.icon(
|
||||
@@ -178,7 +198,7 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
// Last used endpoint
|
||||
if (connector.activeTcpEndpoint != null &&
|
||||
connector.isTcpTransportConnected) ...[
|
||||
const SectionHeader('CONNECTED TO'),
|
||||
SectionHeader(context.l10n.tcpConnectedToHeader),
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
@@ -188,7 +208,7 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
children: [
|
||||
Icon(
|
||||
Icons.lan,
|
||||
size: 16,
|
||||
size: 20,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
@@ -196,7 +216,7 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
child: Text(
|
||||
connector.activeTcpEndpoint!,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
fontSize: 15,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
maxLines: 1,
|
||||
@@ -283,12 +303,15 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
|
||||
final host = _hostController.text.trim();
|
||||
final parsedPort = int.tryParse(_portController.text.trim());
|
||||
if (host.isEmpty) {
|
||||
_showError(context.l10n.tcpErrorHostRequired);
|
||||
return;
|
||||
}
|
||||
if (parsedPort == null || parsedPort < 1 || parsedPort > 65535) {
|
||||
_showError(context.l10n.tcpErrorPortInvalid);
|
||||
final hostError = host.isEmpty ? context.l10n.tcpErrorHostRequired : null;
|
||||
final portError = parsedPort == null || parsedPort < 1 || parsedPort > 65535
|
||||
? context.l10n.tcpErrorPortInvalid
|
||||
: null;
|
||||
setState(() {
|
||||
_hostError = hostError;
|
||||
_portError = portError;
|
||||
});
|
||||
if (hostError != null || portError != null || parsedPort == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,27 +135,17 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
_tripTime = reader.readUInt32LE();
|
||||
_statusTimeout?.cancel();
|
||||
final isAutoRefreshRequest = _activeTelemetryRequestIsAutoRefresh;
|
||||
_statusTimeout = Timer(Duration(milliseconds: _tripTime), () {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = false;
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_autoRefreshLastAttemptFailed = true;
|
||||
}
|
||||
});
|
||||
if (!isAutoRefreshRequest) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.telemetry_requestTimeout),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_scheduleNextAutoRefreshAttempt();
|
||||
}
|
||||
_recordTelemetryResult(false);
|
||||
});
|
||||
_statusTimeout = Timer(
|
||||
Duration(milliseconds: _tripTime),
|
||||
() => _handleRequestFailed(isAutoRefreshRequest),
|
||||
);
|
||||
}
|
||||
|
||||
// The radio rejected the send: fail now instead of waiting forever.
|
||||
if (cmd == respCodeErr && _awaitingSent) {
|
||||
_awaitingSent = false;
|
||||
_statusTimeout?.cancel();
|
||||
_handleRequestFailed(_activeTelemetryRequestIsAutoRefresh);
|
||||
}
|
||||
|
||||
// Check if it's a binary response
|
||||
@@ -183,6 +173,30 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Ends a telemetry request that timed out or was rejected by the radio.
|
||||
void _handleRequestFailed(bool isAutoRefreshRequest) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = false;
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_autoRefreshLastAttemptFailed = true;
|
||||
}
|
||||
_activeTelemetryRequestIsAutoRefresh = false;
|
||||
});
|
||||
if (!isAutoRefreshRequest) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.telemetry_requestTimeout),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_scheduleNextAutoRefreshAttempt();
|
||||
}
|
||||
_recordTelemetryResult(false);
|
||||
}
|
||||
|
||||
void _handleTelemetryResponse(Uint8List frame) {
|
||||
final parsedTelemetry = CayenneLpp.parseByChannel(frame);
|
||||
final batteryMv = _extractTelemetryBatteryMillivolts(parsedTelemetry);
|
||||
@@ -239,28 +253,10 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
frame = buildSendTelemetryReq(null);
|
||||
final isAutoRefreshRequest = _activeTelemetryRequestIsAutoRefresh;
|
||||
_statusTimeout?.cancel();
|
||||
_statusTimeout = Timer(const Duration(seconds: 5), () {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = false;
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_autoRefreshLastAttemptFailed = true;
|
||||
}
|
||||
_activeTelemetryRequestIsAutoRefresh = false;
|
||||
});
|
||||
if (!isAutoRefreshRequest) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.telemetry_requestTimeout),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_scheduleNextAutoRefreshAttempt();
|
||||
}
|
||||
_recordTelemetryResult(false);
|
||||
});
|
||||
_statusTimeout = Timer(
|
||||
const Duration(seconds: 5),
|
||||
() => _handleRequestFailed(isAutoRefreshRequest),
|
||||
);
|
||||
} else {
|
||||
final selection = await connector.preparePathForContactSend(
|
||||
_resolveContact(connector),
|
||||
@@ -446,7 +442,26 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
if (!_isLoaded &&
|
||||
if (_isLoading &&
|
||||
!_hasData &&
|
||||
(_parsedTelemetry == null || _parsedTelemetry!.isEmpty))
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Column(
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.telemetry_loading,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
else if (!_isLoaded &&
|
||||
!_hasData &&
|
||||
(_parsedTelemetry == null || _parsedTelemetry!.isEmpty))
|
||||
Center(
|
||||
@@ -506,7 +521,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
bool isImperialUnits,
|
||||
) {
|
||||
if (entry.key == 'gps') {
|
||||
return _buildGpsInfo(entry.value);
|
||||
return _buildGpsInfo(entry.value, isImperialUnits);
|
||||
}
|
||||
|
||||
final display = _formatTelemetryField(
|
||||
@@ -573,7 +588,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
case 'altitude':
|
||||
return _TelemetryFieldDisplay(
|
||||
l10n.telemetry_altitudeLabel,
|
||||
l10n.telemetry_altitudeValue(text),
|
||||
_lengthText(value, isImperialUnits, altitude: true),
|
||||
);
|
||||
case 'voltage':
|
||||
return _TelemetryFieldDisplay(
|
||||
@@ -612,7 +627,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
case 'distance':
|
||||
return _TelemetryFieldDisplay(
|
||||
l10n.telemetry_distanceLabel,
|
||||
l10n.telemetry_distanceValue(text),
|
||||
_lengthText(value, isImperialUnits, altitude: false),
|
||||
);
|
||||
case 'energy':
|
||||
return _TelemetryFieldDisplay(
|
||||
@@ -863,7 +878,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
return value;
|
||||
}
|
||||
|
||||
Widget _buildGpsInfo(dynamic value) {
|
||||
Widget _buildGpsInfo(dynamic value, bool isImperialUnits) {
|
||||
final latitude = _readGpsValue(value, 'latitude');
|
||||
final longitude = _readGpsValue(value, 'longitude');
|
||||
final altitude = _readGpsValue(value, 'altitude');
|
||||
@@ -872,7 +887,13 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
? [
|
||||
latitude!.toStringAsFixed(5),
|
||||
longitude!.toStringAsFixed(5),
|
||||
if (altitude != null) '${altitude.toStringAsFixed(1)} m',
|
||||
if (altitude != null)
|
||||
_lengthText(
|
||||
altitude,
|
||||
isImperialUnits,
|
||||
altitude: true,
|
||||
metricText: altitude.toStringAsFixed(1),
|
||||
),
|
||||
].join(', ')
|
||||
: value.toString();
|
||||
|
||||
@@ -927,7 +948,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
final x = _telemetryValueText(value['x']);
|
||||
final y = _telemetryValueText(value['y']);
|
||||
final z = _telemetryValueText(value['z']);
|
||||
return 'X: $x, Y: $y, Z: $z';
|
||||
return context.l10n.telemetry_axisValue(x, y, z);
|
||||
}
|
||||
|
||||
String _telemetryColorText(dynamic value) {
|
||||
@@ -935,7 +956,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
final red = _telemetryValueText(value['red']);
|
||||
final green = _telemetryValueText(value['green']);
|
||||
final blue = _telemetryValueText(value['blue']);
|
||||
return 'R: $red, G: $green, B: $blue';
|
||||
return context.l10n.telemetry_colourValue(red, green, blue);
|
||||
}
|
||||
|
||||
String _telemetryMapText(dynamic value) {
|
||||
@@ -1019,6 +1040,32 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Formats a length reported in meters, converting to feet in imperial mode.
|
||||
String _lengthText(
|
||||
dynamic meters,
|
||||
bool isImperialUnits, {
|
||||
required bool altitude,
|
||||
String? metricText,
|
||||
}) {
|
||||
final l10n = context.l10n;
|
||||
if (meters is! num) {
|
||||
final text = _telemetryValueText(meters);
|
||||
return altitude
|
||||
? l10n.telemetry_altitudeValue(text)
|
||||
: l10n.telemetry_distanceValue(text);
|
||||
}
|
||||
if (isImperialUnits) {
|
||||
final feet = (meters * 3.28084).toStringAsFixed(1);
|
||||
return altitude
|
||||
? l10n.telemetry_altitudeValueFeet(feet)
|
||||
: l10n.telemetry_distanceValueFeet(feet);
|
||||
}
|
||||
final text = metricText ?? _telemetryValueText(meters);
|
||||
return altitude
|
||||
? l10n.telemetry_altitudeValue(text)
|
||||
: l10n.telemetry_distanceValue(text);
|
||||
}
|
||||
|
||||
String _temperatureText(double? tempC, bool isImperialUnits) {
|
||||
final l10n = context.l10n;
|
||||
if (tempC == null) return l10n.common_notAvailable;
|
||||
|
||||
@@ -24,7 +24,7 @@ class UsbScreen extends StatefulWidget {
|
||||
State<UsbScreen> createState() => _UsbScreenState();
|
||||
}
|
||||
|
||||
class _UsbScreenState extends State<UsbScreen> {
|
||||
class _UsbScreenState extends State<UsbScreen> with WidgetsBindingObserver {
|
||||
final List<String> _ports = <String>[];
|
||||
bool _isLoadingPorts = true;
|
||||
bool _navigatedToChannels = false;
|
||||
@@ -36,6 +36,13 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
bool get _supportsHotPlug =>
|
||||
PlatformInfo.isWindows || PlatformInfo.isLinux || PlatformInfo.isMacOS;
|
||||
|
||||
/// Web Serial lists a synthetic "request a port" entry plus ports the user
|
||||
/// already authorised; the request entry opens the browser's port picker.
|
||||
static const String _webRequestPortName = 'web:request';
|
||||
|
||||
bool _isWebRequestEntry(String port) =>
|
||||
normalizeUsbPortName(port) == _webRequestPortName;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -55,9 +62,25 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
}
|
||||
};
|
||||
_connector.addListener(_connectionListener);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_startHotPlugTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// Polling the serial ports in the background wastes power; stop while
|
||||
// the app isn't in the foreground and resume when it returns.
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
if (_supportsHotPlug && _hotPlugTimer == null) {
|
||||
_startHotPlugTimer();
|
||||
unawaited(_pollHotPlug());
|
||||
}
|
||||
} else {
|
||||
_hotPlugTimer?.cancel();
|
||||
_hotPlugTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@@ -71,6 +94,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_hotPlugTimer?.cancel();
|
||||
_hotPlugTimer = null;
|
||||
_connector.removeListener(_connectionListener);
|
||||
@@ -125,7 +149,8 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
},
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: _supportsHotPlug
|
||||
// Desktop hot-plugs automatically; web uses the port-picker button.
|
||||
bottomNavigationBar: _supportsHotPlug || PlatformInfo.isWeb
|
||||
? null
|
||||
: SafeArea(
|
||||
top: false,
|
||||
@@ -227,6 +252,14 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
Widget _buildPortList(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
|
||||
final isConnecting =
|
||||
connector.state == MeshCoreConnectionState.connecting &&
|
||||
connector.activeTransport == MeshCoreTransportType.usb;
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
return _buildWebPortPicker(context, connector, isConnecting);
|
||||
}
|
||||
|
||||
if (_isLoadingPorts) {
|
||||
return EmptyState(icon: Icons.usb, title: l10n.usbStatus_searching);
|
||||
}
|
||||
@@ -235,15 +268,67 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
return EmptyState(icon: Icons.usb, title: l10n.usbScreenEmptyState);
|
||||
}
|
||||
|
||||
final isConnecting =
|
||||
connector.state == MeshCoreConnectionState.connecting &&
|
||||
connector.activeTransport == MeshCoreTransportType.usb;
|
||||
return _buildPortListView(context, _ports, isConnecting);
|
||||
}
|
||||
|
||||
/// Web: one prominent button opens the browser's serial-port picker;
|
||||
/// ports the user already authorised are listed below it for reconnects.
|
||||
Widget _buildWebPortPicker(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
bool isConnecting,
|
||||
) {
|
||||
final authorizedPorts = _ports
|
||||
.where((port) => !_isWebRequestEntry(port))
|
||||
.toList();
|
||||
final canConnect =
|
||||
!isConnecting &&
|
||||
connector.state == MeshCoreConnectionState.disconnected;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
child: FilledButton.icon(
|
||||
key: const Key('usb_choose_serial_port_button'),
|
||||
style: FilledButton.styleFrom(minimumSize: const Size(0, 56)),
|
||||
onPressed: canConnect
|
||||
? () {
|
||||
HapticFeedback.selectionClick();
|
||||
_connectPort(_webRequestPortName);
|
||||
}
|
||||
: null,
|
||||
icon: isConnecting
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.usb),
|
||||
label: Text(
|
||||
context.l10n.usbChooseSerialPort,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (authorizedPorts.isNotEmpty)
|
||||
Expanded(
|
||||
child: _buildPortListView(context, authorizedPorts, isConnecting),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPortListView(
|
||||
BuildContext context,
|
||||
List<String> ports,
|
||||
bool isConnecting,
|
||||
) {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
itemCount: _ports.length,
|
||||
itemCount: ports.length,
|
||||
itemBuilder: (context, index) {
|
||||
final port = _ports[index];
|
||||
final port = ports[index];
|
||||
final displayName = friendlyUsbPortName(port);
|
||||
final rawName = normalizeUsbPortName(port);
|
||||
final showRawName =
|
||||
@@ -279,7 +364,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
? Text(
|
||||
rawName,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
fontSize: 13,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
maxLines: 1,
|
||||
@@ -288,7 +373,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
: null,
|
||||
trailing: Icon(
|
||||
Icons.chevron_right,
|
||||
size: 18,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
@@ -309,6 +394,8 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
Future<void> _pollHotPlug() async {
|
||||
if (_isLoadingPorts) return;
|
||||
if (!mounted) return;
|
||||
// Skip while another screen covers this one.
|
||||
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
|
||||
// Don't poll while connecting or connected.
|
||||
if (_connector.state != MeshCoreConnectionState.disconnected) return;
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user