PrfEncoded<TSource, TStore> constructor
PrfEncoded<TSource, TStore> (})
Creates a new PrfEncoded variable with the specified encoding and decoding functions.
Parameters:
key
: Unique identifier for the variable in SharedPreferencesfrom
: Function to decode from storage typeTStore
to source typeTSource
to
: Function to encode from source typeTSource
to storage typeTStore
getter
: Function to retrieve the encoded value from SharedPreferencessetter
: Function to save the encoded value to SharedPreferencesdefaultValue
: Optional default value to use when no value is stored
Implementation
PrfEncoded(
String key, {
required Decode<TSource, TStore> from,
required Encode<TSource, TStore> to,
required Future<TStore?> Function(SharedPreferencesAsync prefs, String key)
getter,
required Future<void> Function(
SharedPreferencesAsync prefs,
String key,
TStore value,
) setter,
TSource? defaultValue,
}) : super(
key,
(prefs, key) async {
final stored = await getter(prefs, key);
return from(stored);
},
(prefs, key, value) async {
final stored = to(value);
await setter(prefs, key, stored);
},
defaultValue,
);