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:
hunteraraujo
2023-09-02 20:27:16 -07:00
parent eaa4825e6b
commit c9bde250b1

View File

@@ -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();
}
}