PrfEncoded<TSource, TStore> class
A specialized PrfVariable that handles encoding and decoding between in-memory types and storage types.
Provides a flexible way to store complex types that aren't directly supported by SharedPreferences by encoding them to supported types before storage and decoding them after retrieval.
Type parameters:
TSource
: The in-memory type used in your application (e.g., DateTime, enum)TStore
: The type used for storage in SharedPreferences (e.g., String, int)
- Inheritance
-
- Object
- PrfVariable<
TSource> - PrfEncoded
- Implementers
- Available extensions
Constructors
-
PrfEncoded.new(String key, {required Decode<
TSource, TStore> from, required Encode<TSource, TStore> to, required Future<TStore?> getter(SharedPreferences prefs, String key), required Future<bool> setter(SharedPreferences prefs, String key, TStore value), TSource? defaultValue}) - Creates a new PrfEncoded variable with the specified encoding and decoding functions.
Properties
- defaultValue → TSource?
-
Default value to use when no value is stored yet.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → String
-
Unique key used to store this variable in SharedPreferences.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
existsOnPrefs(
) → Future< bool> -
Available on PrfVariable<
Checks if the key exists in SharedPreferences.T> , provided by the PrfVariableExtensions extension -
get(
) → Future< T?> -
Available on PrfVariable<
Gets the stored value associated with this variable.T> , provided by the PrfVariableExtensions extension -
getOrFallback(
T fallback) → Future< T> -
Available on PrfVariable<
Gets the stored value or returns a fallback if the value is null.T> , provided by the PrfVariableExtensions extension -
getValue(
SharedPreferences prefs) → Future< TSource?> -
Retrieves the current value from cache or SharedPreferences.
inherited
-
isNull(
) → Future< bool> -
Available on PrfVariable<
Checks if the current value is null in storage.T> , provided by the PrfVariableExtensions extension -
isValueNull(
SharedPreferences prefs) → Future< bool> -
Checks if the current value is null.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
) → Future< void> -
Available on PrfVariable<
Removes the value from persistent storage.T> , provided by the PrfVariableExtensions extension -
removeValue(
SharedPreferences prefs) → Future< void> -
Removes the value from both the cache and SharedPreferences.
inherited
-
set(
T value) → Future< bool> -
Available on PrfVariable<
Sets the value for this variable in persistent storage.T> , provided by the PrfVariableExtensions extension -
setValue(
SharedPreferences prefs, TSource value) → Future< bool> -
Saves a new value to SharedPreferences and updates the cache.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited