Apply Settings changes to the live BackendAPI without restart

Settings._save wrote new base_url/api_key to prefs but the BackendAPI
singleton kept the Dio it built at first access, so URL/key changes only
took effect after an app restart. Expose reconfigureFromPrefs() on
BackendAPI and call it from Settings._save so subsequent requests pick up
the new config immediately.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-31 09:17:15 -04:00
co-authored by Claude Opus 4.7
parent 7954a9c755
commit d3b6c64e8b
2 changed files with 5 additions and 0 deletions
+1
View File
@@ -71,6 +71,7 @@ class _SettingsState extends State<Settings> {
if (!_formKey.currentState!.validate()) return;
PrefUtil.setValue('base_url', _baseUrlController.text);
PrefUtil.setValue('api_key', XOR().xorEncode(_apiKeyController.text));
BackendAPI.instance.reconfigureFromPrefs();
context.read<AppState>().setTheme(_selectedTheme);
UISnackbars.showSuccess(context, 'Settings saved successfully');
}
+4
View File
@@ -57,6 +57,10 @@ class BackendAPI {
static BackendAPI get instance => _instance;
BackendAPI._internal() {
reconfigureFromPrefs();
}
void reconfigureFromPrefs() {
_baseUrl =
PrefUtil.getValue("base_url", "http://localhost:3000/api") as String;
_apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String);