json<T> static method
Creates a new preference for a JSON-serializable object.
This factory method sets up a Prf instance with a JsonAdapter for converting between the object and its JSON representation.
key
is the key to store the preference under.fromJson
converts a JSON map to an instance of typeT
.toJson
converts an instance of typeT
to a JSON map.defaultValue
is the value to use if no value exists for the key.
Implementation
static Prf<T> json<T>(
String key, {
required T Function(Map<String, dynamic> json) fromJson,
required Map<String, dynamic> Function(T object) toJson,
T? defaultValue,
}) {
return Prf._withAdapter(
key,
adapter: JsonAdapter<T>(fromJson: fromJson, toJson: toJson),
defaultValue: defaultValue,
);
}