@@ -36,7 +36,7 @@ class ConfigProvider with ChangeNotifier {
3636 fetchConfig ();
3737 }
3838
39- Future <void > fetchConfig ({int retries = 3 }) async {
39+ Future <void > fetchConfig ({int retries = 9 }) async {
4040 _isLoading = true ;
4141 _error = null ;
4242 notifyListeners ();
@@ -50,11 +50,13 @@ class ConfigProvider with ChangeNotifier {
5050 } catch (e) {
5151 attempt++ ;
5252 final msg = e.toString ();
53- if (attempt <= retries &&
54- (msg.contains ("Invalid response line" ) || msg.contains ("Connection closed" ) || msg.contains ("Connection refused" ))) {
53+ if (attempt <= retries &&
54+ (msg.contains ("Invalid response line" ) ||
55+ msg.contains ("Connection closed" ) ||
56+ msg.contains ("Connection refused" ))) {
5557 // Wait a bit for server to come back up
5658 await Future .delayed (Duration (milliseconds: 500 * attempt));
57- continue ;
59+ continue ;
5860 }
5961 _error = "Attempt $attempt failed:\n $msg " ;
6062 }
@@ -71,14 +73,15 @@ class ConfigProvider with ChangeNotifier {
7173
7274 try {
7375 await _apiService.saveConfig (newConfig);
74- _config = newConfig;
75- // After a successful save, the server will restart.
76+ _config = newConfig;
77+ // After a successful save, the server will restart.
7678 // We give it a moment then fetch the latest state to confirm.
7779 await Future .delayed (const Duration (milliseconds: 500 ));
7880 await fetchConfig ();
7981 } catch (e) {
8082 final msg = e.toString ();
81- if (msg.contains ("Invalid response line" ) || msg.contains ("Connection closed" )) {
83+ if (msg.contains ("Invalid response line" ) ||
84+ msg.contains ("Connection closed" )) {
8285 // Server likely restarted immediately after save. Treat as success and reload.
8386 await fetchConfig ();
8487 return ;
@@ -89,19 +92,31 @@ class ConfigProvider with ChangeNotifier {
8992 notifyListeners ();
9093 }
9194 }
92-
95+
9396 void toggleProducer (String producerName, bool isEnabled) {
94- if (_config == null ) return ;
95-
97+ if (_config == null ) return ;
98+
9699 switch (producerName) {
97- case 'SensorLED' : _config! .sensorLED.enabled = isEnabled; break ;
98- case 'NightLED' : _config! .nightLED.enabled = isEnabled; break ;
99- case 'ClockLED' : _config! .clockLED.enabled = isEnabled; break ;
100- case 'AudioLED' : _config! .audioLED.enabled = isEnabled; break ;
101- case 'CylonLED' : _config! .cylonLED.enabled = isEnabled; break ;
102- case 'MultiBlobLED' : _config! .multiBlobLED.enabled = isEnabled; break ;
100+ case 'SensorLED' :
101+ _config! .sensorLED.enabled = isEnabled;
102+ break ;
103+ case 'NightLED' :
104+ _config! .nightLED.enabled = isEnabled;
105+ break ;
106+ case 'ClockLED' :
107+ _config! .clockLED.enabled = isEnabled;
108+ break ;
109+ case 'AudioLED' :
110+ _config! .audioLED.enabled = isEnabled;
111+ break ;
112+ case 'CylonLED' :
113+ _config! .cylonLED.enabled = isEnabled;
114+ break ;
115+ case 'MultiBlobLED' :
116+ _config! .multiBlobLED.enabled = isEnabled;
117+ break ;
103118 }
104-
119+
105120 updateConfig (_config! );
106121 }
107122}
0 commit comments