From 818f514702011bc4ed5dd1c8a4b3619b45483953 Mon Sep 17 00:00:00 2001 From: Zach Date: Sun, 1 Feb 2026 17:08:53 -0700 Subject: [PATCH] The first issue was that the toggle switch states weren't being initialized when settings were refreshed from the device. The code would correctly update the interval values themselves, but failed to set the corresponding boolean flags that control whether the toggles appear as "on" or "off". This meant that if you refreshed settings from a device that had advertisements disabled (with an interval of zero), the toggles would incorrectly show as enabled even though the device was actually broadcasting no advertisements. We fixed this by adding two lines that explicitly set _advertEnable = _advertInterval > 0 and _floodAdvertEnable = _floodAdvertInterval > 0 after parsing the interval values from device responses. The second critical bug was in the validation logic that checks whether responses from the device contain valid data. The validator was rejecting any interval values of zero because it checked interval > 0, but zero is now a meaningful and valid value that indicates advertisements are disabled. Without this fix, any time a device reported back that advertisements were disabled, the app would silently discard that information as invalid, leaving the UI out of sync with reality. We changed the validation to use interval >= 0 instead and updated the comment to explicitly document that zero means disabled. The third fix was a minor code style issue where a single-line if statement was missing braces, causing a linter warning. This doesn't affect functionality but ensures the code meets project standards. --- lib/screens/repeater_settings_screen.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/screens/repeater_settings_screen.dart b/lib/screens/repeater_settings_screen.dart index 018caef..bae0f50 100644 --- a/lib/screens/repeater_settings_screen.dart +++ b/lib/screens/repeater_settings_screen.dart @@ -248,12 +248,14 @@ class _RepeaterSettingsScreenState extends State { _fetchedSettings['advert.interval']!, _advertInterval, ); + _advertEnable = _advertInterval > 0; } if (_fetchedSettings.containsKey('flood.advert.interval')) { _floodAdvertInterval = _parseIntWithFallback( _fetchedSettings['flood.advert.interval']!, _floodAdvertInterval, ); + _floodAdvertEnable = _floodAdvertInterval > 0; } if (_fetchedSettings.containsKey('priv.advert.interval')) { _privAdvertInterval = _parseIntWithFallback( @@ -379,18 +381,19 @@ class _RepeaterSettingsScreenState extends State { case 'advert.interval': case 'flood.advert.interval': case 'priv.advert.interval': - // Interval: positive integer + // Interval: non-negative integer (0 means disabled) if (value.contains(',')) return false; final interval = int.tryParse(value.replaceAll(RegExp(r'[^0-9]'), '')); - return interval != null && interval > 0; + return interval != null && interval >= 0; case 'name': // Name: any non-empty string, but should NOT look like radio settings if (value.isEmpty) return false; // If it has 3+ commas and looks like numbers, probably radio data final commaCount = ','.allMatches(value).length; - if (commaCount >= 3 && RegExp(r'^[\d.,\s]+$').hasMatch(value)) + if (commaCount >= 3 && RegExp(r'^[\d.,\s]+$').hasMatch(value)) { return false; + } return true; default: