fromJson static method

FormComponent<DataEntity> fromJson(
  1. dynamic json,
  2. dynamic schema
)

Mapping to a concrete implementation based on json and schema

Throws an ArgumentError if not matching implementation is found.

Implementation

// missing_return can be ignored as the switch statement is exhaustive
// ignore: missing_return
static FormComponent fromJson(dynamic json, dynamic schema) {
  final properties = schema['properties'][json['fieldId']];
  if (properties == null) {
    throw ArgumentError(
        'No Schema Entry found for ${json['property']} with id ${json['fieldId']}');
  }
  final dataType = dataTypeFromSchemaProperty(schemaProperty: properties);
  switch (dataType) {
    case DataType.text:
      return StringFormComponent.fromJson(json);
    case DataType.dateTime:
      return DateTimeFormComponent.fromJson(json);
    case DataType.date:
      return DateFormComponent.fromJson(json);
    case DataType.integer:
      return IntegerFormComponent.fromJson(json);
    case DataType.checkbox:
      return BooleanFormComponent.fromJson(json);
    case DataType.selectionBox:
      return EnumFormComponent.fromJson(json, properties);
  }
}