mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 02:54:10 +00:00
* Feature: Add Theme selection in Settings page * Fix: Theme provider exception handling. * feat(mobile): Show theme selection option in settings screen. * BuildID version 9 --------- Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
43 lines
1.1 KiB
Dart
43 lines
1.1 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class PreferencesService {
|
|
static const _groupByTypeKey = 'dashboard_group_by_type';
|
|
static const _themeModeKey = 'theme_mode';
|
|
|
|
static PreferencesService? _instance;
|
|
SharedPreferences? _prefs;
|
|
|
|
PreferencesService._();
|
|
|
|
static PreferencesService get instance {
|
|
_instance ??= PreferencesService._();
|
|
return _instance!;
|
|
}
|
|
|
|
Future<SharedPreferences> get _preferences async {
|
|
_prefs ??= await SharedPreferences.getInstance();
|
|
return _prefs!;
|
|
}
|
|
|
|
Future<bool> getGroupByType() async {
|
|
final prefs = await _preferences;
|
|
return prefs.getBool(_groupByTypeKey) ?? false;
|
|
}
|
|
|
|
Future<void> setGroupByType(bool value) async {
|
|
final prefs = await _preferences;
|
|
await prefs.setBool(_groupByTypeKey, value);
|
|
}
|
|
|
|
/// Returns 'light', 'dark', or 'system' (default).
|
|
Future<String> getThemeMode() async {
|
|
final prefs = await _preferences;
|
|
return prefs.getString(_themeModeKey) ?? 'system';
|
|
}
|
|
|
|
Future<void> setThemeMode(String mode) async {
|
|
final prefs = await _preferences;
|
|
await prefs.setString(_themeModeKey, mode);
|
|
}
|
|
}
|