jsonToField<T extends Field> static method

T jsonToField<T extends Field>(
  1. dynamic json
)

Implementation

static T jsonToField<T extends Field>(dynamic json) {
  final String? type = json[fieldTypeProperty] as String?;
  if (type == null) {
    throw Exception('Json representation of "$Field" should contain a value with key "$fieldTypeProperty"');
  }
  if (type == FieldType.binaryField.name) {
    return BinaryField.fromJson(json) as T;
  } else if (type == FieldType.boolField.name) {
    return BoolField.fromJson(json) as T;
  } else if (type == FieldType.colorField.name) {
    return ColorField.fromJson(json) as T;
  } else if (type == FieldType.dateField.name) {
    return DateTimeField.fromJson(json) as T;
  } else if (type == FieldType.enumField.name) {
    return EnumField.fromJson(json) as T;
  } else if (type == FieldType.fontField.name) {
    return FontField.fromJson(json) as T;
  } else if (type == FieldType.headerField.name) {
    return HeaderField.fromJson(json) as T;
  } else if (type == FieldType.iconField.name) {
    return IconField.fromJson(json) as T;
  } else if (type == FieldType.idField.name) {
    return IdField.fromJson(json) as T;
  } else if (type == FieldType.modelsSelectorField.name) {
    return ModelsSelectorField.fromJson(json) as T;
  } else if (type == FieldType.stringField.name) {
    return StringField.fromJson(json) as T;
  } else if (type == FieldType.multiSelectorField.name) {
    return MultiSelectorField.fromJson(json) as T;
  } else if (type == FieldType.numberField.name) {
    return NumberField.fromJson(json) as T;
  } else if (type == FieldType.queryFilterField.name) {
    return QueryFilterField.fromJson(json) as T;
  } else if (type == FieldType.queryFilterValueField.name) {
    return QueryFilterValueField.fromJson(json) as T;
  } else if (type == FieldType.screenField.name) {
    return ScreenField.fromJson(json) as T;
  } else if (type == FieldType.selectorField.name) {
    return SelectorField.fromJson(json) as T;
  } else if (type == FieldType.structureField.name) {
    return StructureField.fromJson(json) as T;
  } else if (type == FieldType.structuredField.name) {
    return StructuredField.fromJson(json) as T;
  } else if (type == FieldType.dynamicField.name) {
    return DynamicField.fromJson(json) as T;
  }
  // TODO(alphamikle): [FIELDS] Add new fields here
  throw UnimplementedError('Not found json decoder for field "$type"');
}