PrfyEnum<T extends Enum> class
An isolate-safe preference object specialized for storing enum values.
This class provides type-safe access to enum values stored in SharedPreferences, without in-memory caching to ensure consistency across isolates. It uses EnumAdapter to convert enum values to their integer indices for storage.
Unlike PrfEnum, this implementation always reads from disk, making it suitable for use in multiple isolates where cached values might become stale.
Example:
enum LogLevel { debug, info, warning, error }
final logLevelPref = PrfyEnum<LogLevel>(
'log_level',
values: LogLevel.values,
defaultValue: LogLevel.info,
);
await logLevelPref.set(LogLevel.warning);
final level = await logLevelPref.get(); // Always reads from disk
- Inheritance
-
- Object
- BasePrfObject<
T> - PrfyEnum
Constructors
-
PrfyEnum.new(String key, {required List<
T> values, T? defaultValue}) - Creates a new isolate-safe enum preference.
Properties
-
adapter
→ EnumAdapter<
T> -
Gets the adapter used to convert between the enum and its storage representation.
no setteroverride
- 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 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.
inherited
-
setValue(
SharedPreferencesAsync prefs, T value) → Future< void> -
Stores
value
in SharedPreferences.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited