plasmoid/lib/settings.dart

71 lines
2 KiB
Dart
Raw Permalink Normal View History

2025-02-24 21:46:40 +02:00
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 _showStatusIcons = true;
bool _hideDemoted = false;
2025-02-24 21:46:40 +02:00
bool get showTags => _showTags;
bool get showIcons => _showIcons;
bool get colorIcons => _colorIcons;
bool get darkTheme => _darkTheme;
bool get sortLastUsed => _sortLastUsed;
bool get autoFocus => _autoFocus;
bool get showStatusIcons => _showStatusIcons;
bool get hideDemoted => _hideDemoted;
2025-02-24 21:46:40 +02:00
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);
_showStatusIcons = _prefsService.getBool('showStatusIcons', true);
_hideDemoted = _prefsService.getBool('hideDemoted', false);
2025-02-24 21:46:40 +02:00
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;
case 'showStatusIcons':
_showStatusIcons = value;
break;
case 'hideDemoted':
_hideDemoted = value;
break;
2025-02-24 21:46:40 +02:00
}
await _prefsService.setBool(key, value);
2026-06-19 14:04:15 +03:00
notifyListeners();
2025-02-24 21:46:40 +02:00
}
}