deepClone<T extends Field> static method

T deepClone<T extends Field>(
  1. T field
)

Implementation

static T deepClone<T extends Field>(T field) {
  final FieldType type = field.type;

  if (type == FieldType.binaryField) {
    return (field as BinaryField).copyWith() as T;
  } else if (type == FieldType.boolField) {
    return (field as BoolField).copyWith() as T;
  } else if (type == FieldType.colorField) {
    return (field as ColorField).copyWith() as T;
  } else if (type == FieldType.dateField) {
    return (field as DateTimeField).copyWith() as T;
  } else if (type == FieldType.enumField) {
    return (field as EnumField).copyWith(values: field.values.map((EnumValue value) => value.copyWith()).toList()) as T;
  } else if (type == FieldType.fontField) {
    return (field as FontField).copyWith() as T;
  } else if (type == FieldType.headerField) {
    return (field as HeaderField).copyWith() as T;
  } else if (type == FieldType.iconField) {
    return (field as IconField).copyWith() as T;
  } else if (type == FieldType.idField) {
    return (field as IdField).copyWith() as T;
  } else if (type == FieldType.modelsSelectorField) {
    return (field as ModelsSelectorField).copyWith() as T;
  } else if (type == FieldType.stringField) {
    return (field as StringField).copyWith() as T;
  } else if (type == FieldType.multiSelectorField) {
    final ThirdTable thirdTable = (field as MultiSelectorField).thirdTable;
    final Model model = field.model;
    return field.copyWith(
      model: model.deepClone(),
      thirdTable: thirdTable.copyWith(
        relationsEntity: thirdTable.relationsEntity.deepClone(),
      ),
    ) as T;
  } else if (type == FieldType.numberField) {
    return (field as NumberField).copyWith() as T;
  } else if (type == FieldType.queryFilterField) {
    return (field as QueryFilterField).copyWith() as T;
  } else if (type == FieldType.queryFilterValueField) {
    return (field as QueryFilterValueField).copyWith() as T;
  } else if (type == FieldType.screenField) {
    return (field as ScreenField).copyWith() as T;
  } else if (type == FieldType.selectorField) {
    return (field as SelectorField).copyWith(
      model: field.model.copyWith(),
    ) as T;
  } else if (type == FieldType.structureField) {
    return (field as StructureField).copyWith() as T;
  } else if (type == FieldType.structuredField) {
    final StructuredField structuredField = field as StructuredField;
    final List<Field> structure = structuredField.structure;
    return structuredField.copyWith(
      structure: structure.map((e) => FieldMapper.deepClone(e)).toList(),
    ) as T;
  } else if (type == FieldType.dynamicField) {
    return (field as DynamicField).copyWith() as T;
  }
  // TODO(alphamikle): [FIELDS] Add new fields here
  throw UnimplementedError('Not found deepClone factory for $Field with type "$type"');
}