initJsonDecoders function

void initJsonDecoders(
  1. Map<Type, ModelDecoderFunction> value
)

Initializes JSON decoders for custom types so they can be easily restored from storage. Call this at the beginning of your app, just before you initialize LiteState controllers.

Decoder MUST be a STATIC function that creates instances of custom classes from a map, e.g.:

static AuthData decode(Map<String, dynamic> map) {
  return AuthData(
    type: map['type'],
    token: map['token'],
    userName: map['userName'],
  );
}

Implementation

void initJsonDecoders(Map<Type, ModelDecoderFunction> value) {
  for (var v in value.entries) {
    final key = v.key.toString();
    if (key.contains('<')) {
      throw 'Encodable type must not be generic. Actual type: $key';
    }
    if (!_jsonDecoders.containsKey(key)) {
      _jsonDecoders[key] = v.value;
    }
  }
}