mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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:
co-authored by
Claude Opus 4.7
parent
7954a9c755
commit
d3b6c64e8b
@@ -71,6 +71,7 @@ class _SettingsState extends State<Settings> {
|
|||||||
if (!_formKey.currentState!.validate()) return;
|
if (!_formKey.currentState!.validate()) return;
|
||||||
PrefUtil.setValue('base_url', _baseUrlController.text);
|
PrefUtil.setValue('base_url', _baseUrlController.text);
|
||||||
PrefUtil.setValue('api_key', XOR().xorEncode(_apiKeyController.text));
|
PrefUtil.setValue('api_key', XOR().xorEncode(_apiKeyController.text));
|
||||||
|
BackendAPI.instance.reconfigureFromPrefs();
|
||||||
context.read<AppState>().setTheme(_selectedTheme);
|
context.read<AppState>().setTheme(_selectedTheme);
|
||||||
UISnackbars.showSuccess(context, 'Settings saved successfully');
|
UISnackbars.showSuccess(context, 'Settings saved successfully');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ class BackendAPI {
|
|||||||
static BackendAPI get instance => _instance;
|
static BackendAPI get instance => _instance;
|
||||||
|
|
||||||
BackendAPI._internal() {
|
BackendAPI._internal() {
|
||||||
|
reconfigureFromPrefs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void reconfigureFromPrefs() {
|
||||||
_baseUrl =
|
_baseUrl =
|
||||||
PrefUtil.getValue("base_url", "http://localhost:3000/api") as String;
|
PrefUtil.getValue("base_url", "http://localhost:3000/api") as String;
|
||||||
_apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String);
|
_apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String);
|
||||||
|
|||||||
Reference in New Issue
Block a user