mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-28 03:14:32 +01:00
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.
27 lines
672 B
Dart
27 lines
672 B
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;
|
|
|
|
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();
|
|
}
|
|
}
|