mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-27 10:54:35 +01:00
Integrate RestApiUtility with ApiSettingsViewModel for Dynamic URL Updates
- Added a reference to RestApiUtility within ApiSettingsViewModel. - Modified _loadBaseURL and updateBaseURL methods to update the base URL in RestApiUtility whenever a change is made. - This ensures that changes to the base URL in the settings are propagated to the utility responsible for making API calls. This integration allows the application to dynamically update the base URL for API calls through the user interface, enhancing flexibility and configurability.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import 'package:auto_gpt_flutter_client/utils/rest_api_utility.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ApiSettingsViewModel with ChangeNotifier {
|
||||
String _baseURL = "http://127.0.0.1:8000";
|
||||
SharedPreferences? _prefs;
|
||||
final RestApiUtility _restApiUtility;
|
||||
|
||||
ApiSettingsViewModel() {
|
||||
ApiSettingsViewModel(this._restApiUtility) {
|
||||
_loadBaseURL();
|
||||
}
|
||||
|
||||
@@ -14,6 +16,7 @@ class ApiSettingsViewModel with ChangeNotifier {
|
||||
void _loadBaseURL() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
_baseURL = _prefs?.getString('baseURL') ?? _baseURL;
|
||||
_restApiUtility.updateBaseURL(_baseURL);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -21,6 +24,7 @@ class ApiSettingsViewModel with ChangeNotifier {
|
||||
_baseURL = newURL;
|
||||
_prefs ??= await SharedPreferences.getInstance();
|
||||
_prefs?.setString('baseURL', newURL);
|
||||
_restApiUtility.updateBaseURL(newURL);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user