add HashMode Setting

This commit is contained in:
ericz
2026-05-18 19:17:53 +02:00
parent 28a5913ba3
commit 73e5b80232
2 changed files with 92 additions and 1 deletions
+84
View File
@@ -298,6 +298,15 @@ class _SettingsScreenState extends State<SettingsScreen> {
onTap: () => pushCompanionRadioStatsScreen(context),
),
const Divider(height: 1),
ListTile(
leading: const Icon(Icons.route_outlined),
title: Text(l10n.repeater_pathHashMode),
subtitle: Text(_pathHashModeSubtitle(connector.pathHashByteWidth)),
trailing: const Icon(Icons.chevron_right),
enabled: connector.isConnected,
onTap: () => _editPathHashMode(context, connector),
),
const Divider(height: 1),
ListTile(
leading: const Icon(Icons.location_on_outlined),
title: Text(l10n.settings_location),
@@ -338,6 +347,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
String _pathHashModeSubtitle(int pathHashByteWidth) {
final width = pathHashByteWidth.clamp(1, 3).toInt();
final mode = width - 1;
final unit = width == 1 ? 'byte' : 'bytes';
return 'Mode $mode - $width $unit per hop';
}
Widget _buildActionsCard(BuildContext context, MeshCoreConnector connector) {
final l10n = context.l10n;
return Card(
@@ -545,6 +561,74 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
void _editPathHashMode(BuildContext context, MeshCoreConnector connector) {
final l10n = context.l10n;
var selectedMode = (connector.pathHashByteWidth - 1).clamp(0, 2).toInt();
showDialog(
context: context,
builder: (dialogContext) => StatefulBuilder(
builder: (context, setDialogState) => AlertDialog(
title: Text(l10n.repeater_pathHashMode),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DropdownButtonFormField<int>(
initialValue: selectedMode,
decoration: InputDecoration(
labelText: l10n.repeater_pathHashMode,
border: const OutlineInputBorder(),
),
items: const [
DropdownMenuItem(value: 0, child: Text('0 - 1 byte')),
DropdownMenuItem(value: 1, child: Text('1 - 2 bytes')),
DropdownMenuItem(value: 2, child: Text('2 - 3 bytes')),
],
onChanged: (value) {
if (value == null) return;
setDialogState(() => selectedMode = value);
},
),
const SizedBox(height: 12),
Text(
l10n.repeater_pathHashModeHelper,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: Text(l10n.common_cancel),
),
FilledButton(
onPressed: () async {
Navigator.pop(dialogContext);
try {
await connector.setPathHashMode(selectedMode);
await connector.refreshDeviceInfo();
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(l10n.repeater_settingsSaved),
);
} catch (e) {
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(l10n.settings_error(e.toString())),
);
}
},
child: Text(l10n.common_save),
),
],
),
),
);
}
void _editLocation(BuildContext context, MeshCoreConnector connector) {
final l10n = context.l10n;
final latController = TextEditingController();