ModelMap constructor
ModelMap(
- dynamic json, {
- 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);
}
}
}