persist method

PersistResult persist(
  1. FutureOr<Storage<String, String>> storage, {
  2. String? key,
  3. String encode(
    1. Settings state
    )?,
  4. Settings decode(
    1. String encoded
    )?,
  5. StorageOptions options = const StorageOptions(),
})
inherited

A variant of persist, for JSON-specific encoding.

You can override key to customize the key used for storage.

Implementation

PersistResult persist(
  FutureOr<Storage<String, String>> storage, {
  String? key,
  String Function(Settings state)? encode,
  Settings Function(String encoded)? decode,
  StorageOptions options = const StorageOptions(),
}) {
  return NotifierPersistX(this).persist<String, String>(
    storage,
    key: key ?? this.key,
    encode: encode ?? $jsonCodex.encode,
    decode: decode ??
        (encoded) {
          final e = $jsonCodex.decode(encoded);
          return Settings.fromJson(e as Map<String, Object?>);
        },
    options: options,
  );
}