mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-27 19:04:25 +01:00
- 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.
31 lines
890 B
Dart
31 lines
890 B
Dart
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(this._restApiUtility) {
|
|
_loadBaseURL();
|
|
}
|
|
|
|
String get baseURL => _baseURL;
|
|
|
|
void _loadBaseURL() async {
|
|
_prefs = await SharedPreferences.getInstance();
|
|
_baseURL = _prefs?.getString('baseURL') ?? _baseURL;
|
|
_restApiUtility.updateBaseURL(_baseURL);
|
|
notifyListeners();
|
|
}
|
|
|
|
void updateBaseURL(String newURL) async {
|
|
_baseURL = newURL;
|
|
_prefs ??= await SharedPreferences.getInstance();
|
|
_prefs?.setString('baseURL', newURL);
|
|
_restApiUtility.updateBaseURL(newURL);
|
|
notifyListeners();
|
|
}
|
|
}
|