mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-28 11:24:30 +01:00
Add ApiSettingsViewModel for managing API base URL
Created a new ViewModel called ApiSettingsViewModel that is responsible for getting and setting the API's base URL. Utilized the shared_preferences package for persistent storage of the base URL.
This commit is contained in:
26
lib/viewmodels/api_settings_viewmodel.dart
Normal file
26
lib/viewmodels/api_settings_viewmodel.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
|
||||
ApiSettingsViewModel() {
|
||||
_loadBaseURL();
|
||||
}
|
||||
|
||||
String get baseURL => _baseURL;
|
||||
|
||||
void _loadBaseURL() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
_baseURL = _prefs?.getString('baseURL') ?? _baseURL;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateBaseURL(String newURL) async {
|
||||
_baseURL = newURL;
|
||||
_prefs ??= await SharedPreferences.getInstance();
|
||||
_prefs?.setString('baseURL', newURL);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user