30 lines
1.0 KiB
Dart
30 lines
1.0 KiB
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'storage_service.dart';
|
|
|
|
/// Typed boundary for non-sensitive preferences and display caches.
|
|
///
|
|
/// Feature code depends on this class instead of constructing or retaining a
|
|
/// [SharedPreferences] instance.
|
|
class PreferencesStorage {
|
|
const PreferencesStorage(this._preferences);
|
|
|
|
final SharedPreferences _preferences;
|
|
|
|
bool getBool(String key, {bool defaultValue = false}) =>
|
|
_preferences.getBool(key) ?? defaultValue;
|
|
String? getString(String key) => _preferences.getString(key);
|
|
bool containsKey(String key) => _preferences.containsKey(key);
|
|
|
|
Future<void> setBool(String key, bool value) =>
|
|
_preferences.setBool(key, value);
|
|
Future<void> setString(String key, String value) =>
|
|
_preferences.setString(key, value);
|
|
Future<void> remove(String key) => _preferences.remove(key);
|
|
}
|
|
|
|
final preferencesStorageProvider = Provider<PreferencesStorage>(
|
|
(ref) => PreferencesStorage(StorageService.to.preferences),
|
|
);
|