map<T> static method

PersistroMastro<Map<String, T>> map<T>(
  1. String key, {
  2. required Map<String, T> initial,
  3. required T fromJson(
    1. dynamic
    ),
  4. bool autoSave = true,
})

Creates a persistent map state container.

Implementation

static PersistroMastro<Map<String, T>> map<T>(
  String key, {
  required Map<String, T> initial,
  required T Function(dynamic) fromJson,
  bool autoSave = true,
}) {
  return PersistroMastro<Map<String, T>>(
    key: key,
    initial: initial,
    decoder: (json) => Map<String, T>.from(
      jsonDecode(json).map((k, v) => MapEntry(k, fromJson(v))),
    ),
    encoder: (value) => jsonEncode(value),
    autoSave: autoSave,
  );
}