mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 22:14:28 +01:00
This commit introduces the `SettingsViewModel` class, part of the MVVM architecture, responsible for managing the state and business logic for the settings feature of the app. This ViewModel is associated with the `SettingsView`. Features Managed by this ViewModel: - Dark Mode: Toggle the state of Dark Mode and notify listeners. - Developer Mode: Toggle the state of Developer Mode and notify listeners. - Base URL: Update the state of Base URL and notify listeners. - Continuous Mode Steps: Increment and decrement the number of Continuous Mode Steps and notify listeners. Each change in the state is followed by a notification to the listeners to rebuild the UI components that depend on this state, ensuring a reactive UI. To-do comments have been added where the state needs to be persisted or synchronized with a server.
56 lines
1.9 KiB
Dart
56 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// [SettingsViewModel] is responsible for managing the state and logic
|
|
/// for the [SettingsView]. It extends [ChangeNotifier] to provide
|
|
/// reactive state management.
|
|
class SettingsViewModel extends ChangeNotifier {
|
|
bool _isDarkModeEnabled = false; // State for Dark Mode
|
|
bool _isDeveloperModeEnabled = false; // State for Developer Mode
|
|
String _baseURL = ''; // State for Base URL
|
|
int _continuousModeSteps = 1; // State for Continuous Mode Steps
|
|
|
|
// Getters to access the private state variables
|
|
bool get isDarkModeEnabled => _isDarkModeEnabled;
|
|
bool get isDeveloperModeEnabled => _isDeveloperModeEnabled;
|
|
String get baseURL => _baseURL;
|
|
int get continuousModeSteps => _continuousModeSteps;
|
|
|
|
/// Toggles the state of Dark Mode and notifies listeners.
|
|
void toggleDarkMode(bool value) {
|
|
_isDarkModeEnabled = value;
|
|
notifyListeners();
|
|
// TODO: Save to local storage or sync with the server
|
|
}
|
|
|
|
/// Toggles the state of Developer Mode and notifies listeners.
|
|
void toggleDeveloperMode(bool value) {
|
|
_isDeveloperModeEnabled = value;
|
|
notifyListeners();
|
|
// TODO: Save to local storage or sync with the server
|
|
}
|
|
|
|
/// Updates the state of Base URL and notifies listeners.
|
|
void updateBaseURL(String value) {
|
|
_baseURL = value;
|
|
notifyListeners();
|
|
// TODO: Save to local storage or sync with the server
|
|
}
|
|
|
|
/// Increments the number of Continuous Mode Steps and notifies listeners.
|
|
void incrementContinuousModeSteps() {
|
|
_continuousModeSteps += 1;
|
|
notifyListeners();
|
|
// TODO: Save to local storage or sync with the server
|
|
}
|
|
|
|
/// Decrements the number of Continuous Mode Steps and notifies listeners.
|
|
void decrementContinuousModeSteps() {
|
|
if (_continuousModeSteps > 1) {
|
|
// Ensure that the number of steps is at least 1
|
|
_continuousModeSteps -= 1;
|
|
notifyListeners();
|
|
// TODO: Save to local storage or sync with the server
|
|
}
|
|
}
|
|
}
|