/// Thin wrapper around [SharedPreferences] for local key-value persistence. library; import 'package:shared_preferences/shared_preferences.dart'; import '../utils/constants.dart'; /// Loads and stores user preferences. Call [init] once at startup. class StorageService { StorageService({this._preferences}); SharedPreferences? _preferences; Future init() async { _preferences ??= await SharedPreferences.getInstance(); } SharedPreferences get _prefs { final prefs = _preferences; if (prefs == null) { throw StateError('StorageService.init() must be called before use.'); } return prefs; } String get themeModeName => _prefs.getString(StorageKeys.themeMode) ?? 'light'; Future setThemeModeName(String value) { return _prefs.setString(StorageKeys.themeMode, value); } /// Serialized Values Sort session JSON, or null when none saved. String? get sortSessionJson => _prefs.getString(StorageKeys.sortSession); Future setSortSessionJson(String json) { return _prefs.setString(StorageKeys.sortSession, json); } Future clearSortSession() { return _prefs.remove(StorageKeys.sortSession); } }