59 lines
1.7 KiB
Dart
59 lines
1.7 KiB
Dart
import "package:flutter/foundation.dart";
|
|
|
|
import "../../src/local_state.dart";
|
|
|
|
class SettingsProvider extends ChangeNotifier {
|
|
SettingsProvider(this._settingsStore) : settings = _settingsStore.settings;
|
|
|
|
static const Map<String, String> _legacyModelAliases = {
|
|
"google/gemini-2.0-flash": "google/gemini-2.0-flash-001",
|
|
};
|
|
|
|
final SettingsStore _settingsStore;
|
|
LocalSettings settings;
|
|
|
|
String normalizeModelId(String? modelId) {
|
|
if (modelId == null || modelId.isEmpty) {
|
|
return "anthropic/claude-sonnet-4.6";
|
|
}
|
|
|
|
return _legacyModelAliases[modelId] ?? modelId;
|
|
}
|
|
|
|
Future<void> updateModel(String newModel) async {
|
|
final normalizedModel = normalizeModelId(newModel);
|
|
await _settingsStore.update(
|
|
(current) => current.copyWith(model: normalizedModel),
|
|
);
|
|
settings = _settingsStore.settings;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> updateApiKey(String newKey) async {
|
|
await _settingsStore.update(
|
|
(current) => current.copyWith(openRouterApiKey: newKey),
|
|
);
|
|
settings = _settingsStore.settings;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> updateTheme(String newTheme) async {
|
|
await _settingsStore.update((current) => current.copyWith(theme: newTheme));
|
|
settings = _settingsStore.settings;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> updateEffortLevel(String newLevel) async {
|
|
await _settingsStore.update(
|
|
(current) => current.copyWith(effortLevel: newLevel),
|
|
);
|
|
settings = _settingsStore.settings;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> resetToDefaults() async {
|
|
await _settingsStore.update((_) => const LocalSettings());
|
|
settings = _settingsStore.settings;
|
|
notifyListeners();
|
|
}
|
|
}
|