ModelMap constructor

ModelMap(
  1. dynamic json, {
  2. Type? type,
})

Implementation

ModelMap(dynamic json, {this.type}) : super(null) {
  if (Model.isRegistering) return;
  if (json is Map) {
    for (final entry in json.entries) {
      final usableType = UsableType(type ?? dynamic);
      final value = usableType.createFromAny(entry.value);
      if (usableType.isRegisteredModel) {
        if (value != null) {
          _fields[entry.key] = ModelField(
              parent: this, options: FieldOptions.defaultOptions, useModelInstanciator: (json) => Model.createByType(type!, json)!);
        }
      } else if (!usableType.isDynamic) {
        if (value != null) _fields[entry.key] = DynamicField(parent: this, options: FieldOptions.defaultOptions).fixedType;
      } else {
        _fields[entry.key] = DynamicField(parent: this, options: FieldOptions.defaultOptions).fixedType;
      }

      _fields[entry.key]?.setFromJson(value);
    }
  }
}