This commit is contained in:
randogoth 2025-02-24 21:46:40 +02:00
parent c065a013fc
commit a88a61cf01
5 changed files with 232 additions and 262 deletions

59
lib/settings.dart Normal file
View file

@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:plasmoid/preferences.dart';
class AppSettings extends ChangeNotifier {
bool _showTags = true;
bool _showIcons = true;
bool _colorIcons = true;
bool _darkTheme = false;
bool _sortLastUsed = true;
bool _autoFocus = true;
bool get showTags => _showTags;
bool get showIcons => _showIcons;
bool get colorIcons => _colorIcons;
bool get darkTheme => _darkTheme;
bool get sortLastUsed => _sortLastUsed;
bool get autoFocus => _autoFocus;
final SharedPreferencesService _prefsService = SharedPreferencesService();
AppSettings() {
_loadSettings();
}
Future<void> _loadSettings() async {
_showTags = _prefsService.getBool('showTags', true);
_showIcons = _prefsService.getBool('showIcons', true);
_colorIcons = _prefsService.getBool('colorIcons', true);
_darkTheme = _prefsService.getBool('darkTheme', false);
_sortLastUsed = _prefsService.getBool('sortLastUsed', true);
_autoFocus = _prefsService.getBool('autoFocus', true);
notifyListeners();
}
Future<void> updateSetting(String key, bool value) async {
switch (key) {
case 'showTags':
_showTags = value;
break;
case 'showIcons':
_showIcons = value;
break;
case 'colorIcons':
_colorIcons = value;
break;
case 'darkTheme':
_darkTheme = value;
break;
case 'sortLastUsed':
_sortLastUsed = value;
break;
case 'autoFocus':
_autoFocus = value;
break;
}
await _prefsService.setBool(key, value);
notifyListeners(); // Notify listeners after updating the setting
}
}