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
Implementers
Available extensions

Constructors

PrfEncoded(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<T>, provided by the PrfVariableExtensions extension

Checks if the key exists in SharedPreferences.
get() → Future<T?>

Available on PrfVariable<T>, provided by the PrfVariableExtensions extension

Gets the stored value associated with this variable.
getOrFallback(T fallback) → Future<T>

Available on PrfVariable<T>, provided by the PrfVariableExtensions extension

Gets the stored value or returns a fallback if the value is null.
getValue(SharedPreferences prefs) → Future<TSource?>
Retrieves the current value from cache or SharedPreferences.
inherited
isNull() → Future<bool>

Available on PrfVariable<T>, provided by the PrfVariableExtensions extension

Checks if the current value is null in storage.
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<T>, provided by the PrfVariableExtensions extension

Removes the value from persistent storage.
removeValue(SharedPreferences prefs) → Future<void>
Removes the value from both the cache and SharedPreferences.
inherited
set(T value) → Future<bool>

Available on PrfVariable<T>, provided by the PrfVariableExtensions extension

Sets the value for this variable in persistent storage.
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