Settings: open dedicated pages instead of dialogs
Node Name, Radio Settings, Location, Contact Settings, Privacy and About now open pages laid out like App Settings. Settings stored on the radio are sent only on Save, with a warning when leaving unsaved changes. - Shared SaveToRadioPage / UnsavedChangesGuard / MeshInfoCard - Node Name byte counter, Location map picker, About links - Export Data refresh; Settings text and title consistency - Radio Settings docs corrected against code and firmware - design.md: settings pages, Save rules, text and app bar rules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
945b82437f
commit
fc7bbe9e02
66 files changed
+7011
-3749
No files matched your search
@@ -1,22 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:meshcore_open/widgets/elements_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/settings_reveal.dart';
|
||||
import '../widgets/radio_settings_dialog.dart';
|
||||
import 'about_screen.dart';
|
||||
import 'app_settings_screen.dart';
|
||||
import 'contact_settings_screen.dart';
|
||||
import 'location_settings_screen.dart';
|
||||
import 'node_name_screen.dart';
|
||||
import 'privacy_settings_screen.dart';
|
||||
import 'radio_settings_screen.dart';
|
||||
import 'app_debug_log_screen.dart';
|
||||
import 'message_filter_settings_screen.dart';
|
||||
import 'ble_debug_log_screen.dart';
|
||||
@@ -38,20 +39,8 @@ class SettingsScreen extends StatefulWidget {
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
bool _showBatteryVoltage = false;
|
||||
bool _deviceInfoExpanded = false;
|
||||
String _appVersion = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadVersionInfo();
|
||||
}
|
||||
|
||||
Future<void> _loadVersionInfo() async {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_appVersion = '${packageInfo.version} BETA';
|
||||
});
|
||||
void _push(BuildContext context, Widget page) {
|
||||
Navigator.push(context, MaterialPageRoute<void>(builder: (_) => page));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -59,11 +48,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
final l10n = context.l10n;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AppBarTitle(
|
||||
l10n.settings_title,
|
||||
indicators: false,
|
||||
subtitle: false,
|
||||
),
|
||||
// A plain title: AppBarTitle fills the bar and stays left-aligned.
|
||||
title: AdaptiveAppBarTitle(l10n.settings_title),
|
||||
centerTitle: true,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
),
|
||||
@@ -186,7 +172,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_export,
|
||||
title: l10n.settings_exportData,
|
||||
subtitle: l10n.settings_exportSubtitle,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
@@ -210,12 +196,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
padding: EdgeInsets.zero,
|
||||
child: MeshNavTile(
|
||||
icon: Icons.info_outline,
|
||||
title: l10n.settings_about,
|
||||
subtitle: l10n.settings_aboutVersion(
|
||||
_appVersion.isEmpty ? l10n.common_loading : _appVersion,
|
||||
),
|
||||
showChevron: false,
|
||||
onTap: () => _showAbout(context),
|
||||
title: l10n.settings_aboutTheApp,
|
||||
onTap: () => _push(context, const AboutScreen()),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -549,7 +531,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
subtitle: connected
|
||||
? connector.selfName ?? l10n.settings_nodeNameNotSet
|
||||
: offline,
|
||||
onTap: connected ? () => _editNodeName(context, connector) : null,
|
||||
onTap: connected
|
||||
? () => _push(context, const NodeNameScreen())
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
@@ -557,7 +541,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
title: l10n.settings_radioSettings,
|
||||
subtitle: connected ? l10n.settings_radioSettingsSubtitle : offline,
|
||||
onTap: connected
|
||||
? () => _showRadioSettings(context, connector)
|
||||
? () => _push(context, RadioSettingsScreen(connector: connector))
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
@@ -606,7 +590,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
icon: Icons.location_on_outlined,
|
||||
title: l10n.settings_location,
|
||||
subtitle: connected ? l10n.settings_locationSubtitle : offline,
|
||||
onTap: connected ? () => _editLocation(context, connector) : null,
|
||||
onTap: connected
|
||||
? () => _push(context, const LocationSettingsScreen())
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
@@ -614,7 +600,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
title: l10n.settings_contactSettings,
|
||||
subtitle: connected ? l10n.settings_contactSettingsSubtitle : offline,
|
||||
onTap: connected
|
||||
? () => _editAutoAddConfig(context, connector)
|
||||
? () => _push(context, const ContactSettingsScreen())
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
@@ -622,7 +608,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
icon: Icons.visibility_off_outlined,
|
||||
title: l10n.settings_privacy,
|
||||
subtitle: connected ? l10n.settings_privacySubtitle : offline,
|
||||
onTap: connected ? () => _privacySettings(context, connector) : null,
|
||||
onTap: connected
|
||||
? () => _push(context, const PrivacySettingsScreen())
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -707,105 +695,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _editNodeName(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
final l10n = context.l10n;
|
||||
final name = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => _NodeNameDialog(initialName: connector.selfName ?? ''),
|
||||
);
|
||||
if (name == null || !context.mounted) return;
|
||||
if (!_ensureConnected(context, connector)) return;
|
||||
try {
|
||||
await connector.setNodeName(name);
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_nodeNameUpdated),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_error(e.toString())),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showRadioSettings(BuildContext context, MeshCoreConnector connector) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RadioSettingsDialog(connector: connector),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _editLocation(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
final l10n = context.l10n;
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
|
||||
// Safe access to custom vars - may be null before device responds
|
||||
final customVars = connector.currentCustomVars ?? {};
|
||||
final bool hasGPS = customVars.containsKey("gps");
|
||||
final bool initialGPSEnabled = customVars["gps"] == "1";
|
||||
|
||||
final edit = await showDialog<_LocationEdit>(
|
||||
context: context,
|
||||
builder: (_) => _LocationDialog(
|
||||
latitude: connector.selfLatitude,
|
||||
longitude: connector.selfLongitude,
|
||||
hasGPS: hasGPS,
|
||||
initialGPSEnabled: initialGPSEnabled,
|
||||
initialIntervalSeconds: settingsService.resolvedGpsIntervalSeconds(
|
||||
customVars,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (edit == null || !edit.hasChanges || !context.mounted) return;
|
||||
if (!_ensureConnected(context, connector)) return;
|
||||
|
||||
try {
|
||||
final gpsEnabled = edit.gpsEnabled;
|
||||
if (gpsEnabled != null) {
|
||||
await connector.setCustomVar(gpsEnabled ? "gps:1" : "gps:0");
|
||||
}
|
||||
final interval = edit.intervalSeconds;
|
||||
if (interval != null) {
|
||||
await settingsService.setGpsIntervalSeconds(
|
||||
interval,
|
||||
writeToDevice: (value) =>
|
||||
connector.setCustomVar("gps_interval:$value"),
|
||||
);
|
||||
}
|
||||
final lat = edit.latitude;
|
||||
final lon = edit.longitude;
|
||||
if (lat != null && lon != null) {
|
||||
await connector.setNodeLocation(lat: lat, lon: lon);
|
||||
}
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
edit.clearsLocation
|
||||
? l10n.settings_locationCleared
|
||||
: l10n.settings_locationUpdated,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_error(e.toString())),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncTime(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
@@ -886,671 +775,4 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAbout(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
showAboutDialog(
|
||||
context: context,
|
||||
applicationName: l10n.appTitle,
|
||||
applicationVersion: _appVersion.isEmpty
|
||||
? l10n.common_loading
|
||||
: _appVersion,
|
||||
applicationLegalese: l10n.settings_aboutLegalese,
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
Text(l10n.settings_aboutDescription),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _editAutoAddConfig(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
// The dialog's context is gone once it pops; report through the screen.
|
||||
final screenContext = context;
|
||||
bool autoAddChat = false;
|
||||
bool autoAddRepeater = false;
|
||||
bool autoAddRoomServer = false;
|
||||
bool autoAddSensor = false;
|
||||
bool overwriteOldest = false;
|
||||
final appSettingsService = context.read<AppSettingsService>();
|
||||
bool evictDiscoveredContactsEnabled =
|
||||
appSettingsService.settings.evictDiscoveredContactsEnabled;
|
||||
bool saving = false;
|
||||
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
autoAddChat = connector.autoAddUsers ?? false;
|
||||
autoAddRepeater = connector.autoAddRepeaters ?? false;
|
||||
autoAddRoomServer = connector.autoAddRoomServers ?? false;
|
||||
autoAddSensor = connector.autoAddSensors ?? false;
|
||||
overwriteOldest = connector.autoAddOverwriteOldest ?? false;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
title: Text(l10n.contactsSettings_autoAddTitle),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FeatureToggleRow(
|
||||
title: l10n.contactsSettings_autoAddUsersTitle,
|
||||
subtitle: l10n.contactsSettings_autoAddUsersSubtitle,
|
||||
value: autoAddChat,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => autoAddChat = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FeatureToggleRow(
|
||||
title: l10n.contactsSettings_autoAddRepeatersTitle,
|
||||
subtitle: l10n.contactsSettings_autoAddRepeatersSubtitle,
|
||||
value: autoAddRepeater,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => autoAddRepeater = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FeatureToggleRow(
|
||||
title: l10n.contactsSettings_autoAddRoomServersTitle,
|
||||
subtitle: l10n.contactsSettings_autoAddRoomServersSubtitle,
|
||||
value: autoAddRoomServer,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => autoAddRoomServer = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FeatureToggleRow(
|
||||
title: l10n.contactsSettings_autoAddSensorsTitle,
|
||||
subtitle: l10n.contactsSettings_autoAddSensorsSubtitle,
|
||||
value: autoAddSensor,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => autoAddSensor = value);
|
||||
},
|
||||
),
|
||||
const Divider(height: 4),
|
||||
FeatureToggleRow(
|
||||
title: l10n.contactsSettings_overwriteOldestTitle,
|
||||
subtitle: l10n.contactsSettings_overwriteOldestSubtitle,
|
||||
value: overwriteOldest,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => overwriteOldest = value);
|
||||
},
|
||||
),
|
||||
const Divider(height: 4),
|
||||
FeatureToggleRow(
|
||||
title: l10n.contactsSettings_evictDiscoveredContactsTitle,
|
||||
subtitle: l10n
|
||||
.contactsSettings_evictDiscoveredContactsSubtitle(
|
||||
MeshCoreConnector.maxDiscoveredContacts,
|
||||
),
|
||||
value: evictDiscoveredContactsEnabled,
|
||||
onChanged: (value) {
|
||||
setDialogState(
|
||||
() => evictDiscoveredContactsEnabled = value,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: saving
|
||||
? null
|
||||
: () async {
|
||||
if (!_ensureConnected(context, connector)) return;
|
||||
setDialogState(() => saving = true);
|
||||
try {
|
||||
await _sendSettings(
|
||||
connector,
|
||||
autoAddChat,
|
||||
autoAddRepeater,
|
||||
autoAddRoomServer,
|
||||
autoAddSensor,
|
||||
overwriteOldest,
|
||||
);
|
||||
await appSettingsService
|
||||
.setEvictDiscoveredContactsEnabled(
|
||||
evictDiscoveredContactsEnabled,
|
||||
);
|
||||
if (evictDiscoveredContactsEnabled) {
|
||||
await connector.trimDiscoveredContactsToLimit();
|
||||
}
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_error(e.toString())),
|
||||
);
|
||||
setDialogState(() => saving = false);
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
Navigator.pop(context);
|
||||
showDismissibleSnackBar(
|
||||
screenContext,
|
||||
content: Text(l10n.settings_contactSettingsSaved),
|
||||
);
|
||||
},
|
||||
child: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _sendSettings(
|
||||
MeshCoreConnector connector,
|
||||
bool autoAddChat,
|
||||
bool autoAddRepeater,
|
||||
bool autoAddRoomServer,
|
||||
bool autoAddSensor,
|
||||
bool overwriteOldest,
|
||||
) async {
|
||||
final frame = buildSetAutoAddConfigFrame(
|
||||
autoAddChat: autoAddChat,
|
||||
autoAddRepeater: autoAddRepeater,
|
||||
autoAddRoomServer: autoAddRoomServer,
|
||||
autoAddSensor: autoAddSensor,
|
||||
overwriteOldest: overwriteOldest,
|
||||
);
|
||||
await connector.sendFrame(frame);
|
||||
await connector.sendFrame(buildGetAutoAddFlagsFrame());
|
||||
}
|
||||
}
|
||||
|
||||
void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
|
||||
int telemetryMode = connector.telemetryModeBase;
|
||||
int telemetryLocMode = connector.telemetryModeLoc;
|
||||
int telemetryEnvMode = connector.telemetryModeEnv;
|
||||
bool advertLocPolicy = connector.advertLocationPolicy == 0 ? false : true;
|
||||
int multiAcks = connector.multiAcks;
|
||||
bool autoZeroHopAdvertOnGpsUpdate =
|
||||
settingsService.settings.autoSendZeroHopAdvertOnGpsUpdate;
|
||||
|
||||
final telemModeBase = [
|
||||
DropdownMenuItem(
|
||||
value: teleModeDeny,
|
||||
child: Text(
|
||||
l10n.settings_denyAll,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: teleModeAllowFlags,
|
||||
child: Text(
|
||||
l10n.settings_allowByContact,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: teleModeAllowAll,
|
||||
child: Text(
|
||||
l10n.settings_allowAll,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
title: Text(l10n.settings_privacy),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.settings_privacySettingsDescription),
|
||||
const SizedBox(height: 16),
|
||||
FeatureToggleRow(
|
||||
title: l10n.settings_advertLocation,
|
||||
subtitle: l10n.settings_advertLocationSubtitle,
|
||||
value: advertLocPolicy,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => advertLocPolicy = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FeatureToggleRow(
|
||||
title: l10n.settings_autoZeroHopAdvertOnGpsUpdate,
|
||||
subtitle: l10n.settings_autoZeroHopAdvertOnGpsUpdateSubtitle,
|
||||
value: autoZeroHopAdvertOnGpsUpdate,
|
||||
enabled: advertLocPolicy,
|
||||
onChanged: advertLocPolicy
|
||||
? (value) {
|
||||
setDialogState(
|
||||
() => autoZeroHopAdvertOnGpsUpdate = value,
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FeatureToggleRow(
|
||||
title: l10n.settings_multiAck,
|
||||
subtitle: l10n.settings_multiAckSubtitle,
|
||||
value: multiAcks == 1,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => multiAcks = value ? 1 : 0);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryBaseMode,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: telemModeBase,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setDialogState(() => telemetryMode = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryLocMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryLocationMode,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: telemModeBase,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setDialogState(() => telemetryLocMode = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryEnvMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryEnvironmentMode,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: telemModeBase,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setDialogState(() => telemetryEnvMode = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.settings_telemetryPerContactHint,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
if (!connector.isConnected) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_notConnectedError),
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await connector.setTelemetryModeBase(
|
||||
telemetryMode,
|
||||
telemetryLocMode,
|
||||
telemetryEnvMode,
|
||||
advertLocPolicy ? 1 : 0,
|
||||
multiAcks,
|
||||
);
|
||||
await settingsService.setAutoSendZeroHopAdvertOnGpsUpdate(
|
||||
autoZeroHopAdvertOnGpsUpdate,
|
||||
);
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_telemetryModeUpdated),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_error(e.toString())),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Node-name editor. Owns (and disposes) its controller; pops with the
|
||||
/// trimmed name on Save, or null on Cancel.
|
||||
class _NodeNameDialog extends StatefulWidget {
|
||||
final String initialName;
|
||||
|
||||
const _NodeNameDialog({required this.initialName});
|
||||
|
||||
@override
|
||||
State<_NodeNameDialog> createState() => _NodeNameDialogState();
|
||||
}
|
||||
|
||||
class _NodeNameDialogState extends State<_NodeNameDialog> {
|
||||
late final TextEditingController _controller = TextEditingController(
|
||||
text: widget.initialName,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return AlertDialog(
|
||||
title: Text(l10n.settings_nodeName),
|
||||
content: TextField(
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.settings_nodeNameHint,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(maxRadioNameBytes),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
ListenableBuilder(
|
||||
listenable: _controller,
|
||||
builder: (context, _) {
|
||||
final name = _controller.text.trim();
|
||||
return TextButton(
|
||||
onPressed: name.isEmpty
|
||||
? null
|
||||
: () => Navigator.pop(context, name),
|
||||
child: Text(l10n.common_save),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// What the location dialog asks the screen to apply. Null fields are left
|
||||
/// unchanged on the device.
|
||||
class _LocationEdit {
|
||||
final bool? gpsEnabled;
|
||||
final int? intervalSeconds;
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
final bool clearsLocation;
|
||||
|
||||
const _LocationEdit({
|
||||
this.gpsEnabled,
|
||||
this.intervalSeconds,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.clearsLocation = false,
|
||||
});
|
||||
|
||||
bool get hasChanges =>
|
||||
gpsEnabled != null ||
|
||||
intervalSeconds != null ||
|
||||
(latitude != null && longitude != null);
|
||||
}
|
||||
|
||||
/// Location / GPS editor. Owns (and disposes) its controllers and validates
|
||||
/// every field before closing, reporting each error under the field it
|
||||
/// belongs to.
|
||||
class _LocationDialog extends StatefulWidget {
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
final bool hasGPS;
|
||||
final bool initialGPSEnabled;
|
||||
final int initialIntervalSeconds;
|
||||
|
||||
const _LocationDialog({
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
required this.hasGPS,
|
||||
required this.initialGPSEnabled,
|
||||
required this.initialIntervalSeconds,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_LocationDialog> createState() => _LocationDialogState();
|
||||
}
|
||||
|
||||
class _LocationDialogState extends State<_LocationDialog> {
|
||||
late final TextEditingController _latController;
|
||||
late final TextEditingController _lonController;
|
||||
late final TextEditingController _intervalController;
|
||||
late bool _isGPSEnabled = widget.initialGPSEnabled;
|
||||
String? _latError;
|
||||
String? _lonError;
|
||||
String? _intervalError;
|
||||
|
||||
/// Firmware stores "no location" as 0,0 (the default for a fresh node), so
|
||||
/// that pair is shown as empty fields rather than a real coordinate.
|
||||
bool get _hasLocation {
|
||||
final lat = widget.latitude;
|
||||
final lon = widget.longitude;
|
||||
return lat != null && lon != null && !(lat == 0 && lon == 0);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_latController = TextEditingController(
|
||||
text: _hasLocation ? widget.latitude!.toStringAsFixed(6) : '',
|
||||
);
|
||||
_lonController = TextEditingController(
|
||||
text: _hasLocation ? widget.longitude!.toStringAsFixed(6) : '',
|
||||
);
|
||||
_intervalController = TextEditingController(
|
||||
text: widget.initialIntervalSeconds.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_latController.dispose();
|
||||
_lonController.dispose();
|
||||
_intervalController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _save() {
|
||||
final l10n = context.l10n;
|
||||
// Validate every field before closing so a typo doesn't discard the
|
||||
// input or leave half the changes applied.
|
||||
int? interval;
|
||||
String? intervalError;
|
||||
if (widget.hasGPS) {
|
||||
final intervalText = _intervalController.text.trim();
|
||||
if (intervalText.isNotEmpty) {
|
||||
interval = int.tryParse(intervalText);
|
||||
if (interval == null || interval < 60 || interval >= 86400) {
|
||||
intervalError = l10n.settings_locationIntervalInvalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final latText = _latController.text.trim();
|
||||
final lonText = _lonController.text.trim();
|
||||
double? lat;
|
||||
double? lon;
|
||||
String? latError;
|
||||
String? lonError;
|
||||
var clearsLocation = false;
|
||||
if (latText.isEmpty && lonText.isEmpty) {
|
||||
// Clearing both fields removes the location. Companion firmware has no
|
||||
// dedicated "clear" command: CMD_SET_ADVERT_LATLON with 0,0 restores
|
||||
// the factory default, which firmware and this app treat as unset.
|
||||
if (_hasLocation) {
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
clearsLocation = true;
|
||||
}
|
||||
} else {
|
||||
// One empty field keeps the device's current value for that axis.
|
||||
lat = latText.isNotEmpty
|
||||
? double.tryParse(latText)
|
||||
: (_hasLocation ? widget.latitude : null);
|
||||
lon = lonText.isNotEmpty
|
||||
? double.tryParse(lonText)
|
||||
: (_hasLocation ? widget.longitude : null);
|
||||
if (lat == null) {
|
||||
latError = latText.isEmpty
|
||||
? l10n.settings_locationBothRequired
|
||||
: l10n.settings_locationInvalid;
|
||||
} else if (lat < -90 || lat > 90) {
|
||||
latError = l10n.settings_locationInvalid;
|
||||
}
|
||||
if (lon == null) {
|
||||
lonError = lonText.isEmpty
|
||||
? l10n.settings_locationBothRequired
|
||||
: l10n.settings_locationInvalid;
|
||||
} else if (lon < -180 || lon > 180) {
|
||||
lonError = l10n.settings_locationInvalid;
|
||||
}
|
||||
}
|
||||
|
||||
if (intervalError != null || latError != null || lonError != null) {
|
||||
setState(() {
|
||||
_intervalError = intervalError;
|
||||
_latError = latError;
|
||||
_lonError = lonError;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.pop(
|
||||
context,
|
||||
_LocationEdit(
|
||||
gpsEnabled: widget.hasGPS && _isGPSEnabled != widget.initialGPSEnabled
|
||||
? _isGPSEnabled
|
||||
: null,
|
||||
intervalSeconds: interval,
|
||||
latitude: lat,
|
||||
longitude: lon,
|
||||
clearsLocation: clearsLocation,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
const coordinateKeyboard = TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
signed: true,
|
||||
);
|
||||
return AlertDialog(
|
||||
title: Text(l10n.settings_location),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _latController,
|
||||
onChanged: (_) {
|
||||
if (_latError != null) setState(() => _latError = null);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_latitude,
|
||||
border: const OutlineInputBorder(),
|
||||
errorText: _latError,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
keyboardType: coordinateKeyboard,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _lonController,
|
||||
onChanged: (_) {
|
||||
if (_lonError != null) setState(() => _lonError = null);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_longitude,
|
||||
border: const OutlineInputBorder(),
|
||||
helperText: l10n.settings_locationClearHelper,
|
||||
helperMaxLines: 2,
|
||||
errorText: _lonError,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
keyboardType: coordinateKeyboard,
|
||||
),
|
||||
if (widget.hasGPS) ...[
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _intervalController,
|
||||
onChanged: (_) {
|
||||
if (_intervalError != null) {
|
||||
setState(() => _intervalError = null);
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_locationIntervalSec,
|
||||
border: const OutlineInputBorder(),
|
||||
errorText: _intervalError,
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: false,
|
||||
signed: false,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FeatureToggleRow(
|
||||
title: l10n.settings_locationGPSEnable,
|
||||
subtitle: l10n.settings_locationGPSEnableSubtitle,
|
||||
value: _isGPSEnabled,
|
||||
// Applied on Save so Cancel leaves the device untouched.
|
||||
onChanged: (value) => setState(() => _isGPSEnabled = value),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(onPressed: _save, child: Text(l10n.common_save)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user