PrfEnum<T extends Enum> class
A cached preference object specialized for storing enum values.
This class provides type-safe access to enum values stored in SharedPreferences, with in-memory caching for improved performance. It uses EnumAdapter to convert enum values to their integer indices for storage.
Example:
enum Theme { light, dark, system }
final themePreference = PrfEnum<Theme>(
'app_theme',
values: Theme.values,
defaultValue: Theme.system,
);
await themePreference.set(Theme.dark);
final currentTheme = await themePreference.get(); // Returns Theme.dark
- Inheritance
-
- Object
- BasePrfObject<
T> - CachedPrfObject<
T> - PrfEnum
- Implementers
Constructors
-
PrfEnum.new(String key, {required List<
T> values, T? defaultValue}) - Creates a new cached enum preference.
Properties
-
adapter
→ EnumAdapter<
T> -
Gets the adapter used to convert between the enum and its storage representation.
no setteroverride
- cachedValue → T?
-
Returns the currently cached value without accessing SharedPreferences.
no setterinherited
- defaultValue → T?
-
Optional default value to use when no value exists for key.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → String
-
The key used to store this preference in SharedPreferences.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getValue(
SharedPreferencesAsync prefs) → Future< T?> -
Gets the value, using the cached value if available or reading from storage if not.
inherited
-
initCache(
SharedPreferencesAsync prefs) → Future< void> -
Initializes the cache by reading the current value from SharedPreferences.
inherited
-
isValueNull(
SharedPreferencesAsync prefs) → Future< bool> -
Checks if the stored value is null.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeValue(
SharedPreferencesAsync prefs) → Future< void> -
Removes the value from SharedPreferences and clears the cached value.
inherited
-
setValue(
SharedPreferencesAsync prefs, T value) → Future< void> -
Stores
value
in SharedPreferences and updates the cached value.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited