getData static method

dynamic getData(
  1. Variable variable, {
  2. int? loop,
  3. ModelFieldGetAttribute? modelAttribute,
  4. Map<ID, ModelEntity>? models,
})

Implementation

static getData(
  Variable variable, {
  int? loop,
  ModelFieldGetAttribute? modelAttribute,
  Map<ID, ModelEntity>? models,
}) {
  switch (variable.runtimeType) {
    case StringVar:
      return (variable as StringVar).data;
    case StringListVar:
      if (loop != null) {
        return (variable as StringListVar).data?[loop];
      }
      return (variable as StringListVar).data;
    case IntVar:
      return (variable as IntVar).data;
    case IntListVar:
      if (loop != null) {
        return (variable as IntListVar).data?[loop];
      }
      return (variable as IntListVar).data;
    case DoubleVar:
      return (variable as DoubleVar).data;
    case DoubleListVar:
      if (loop != null) {
        return (variable as DoubleListVar).data?[loop];
      }
      return (variable as DoubleListVar).data;
    case BoolVar:
      return (variable as BoolVar).data;
    case BoolListVar:
      if (loop != null) {
        return (variable as BoolListVar).data?[loop];
      }
      return (variable as BoolListVar).data;
    case JsonVar:
      return (variable as JsonVar).data;
    case EnumVar:
      return (variable as EnumVar).value;
    case DateTimeVar:
      return (variable as DateTimeVar).data;
    case DateTimeListVar:
      if (loop != null) {
        return (variable as DateTimeListVar).data?[loop];
      }
      return (variable as DateTimeListVar).data;
    case ModelVar:
      final model =
          (variable as ModelVar).model ?? models?[(variable).modelID];
      assert(model != null, 'Model not found');
      final field = model!.fields
          .firstWhereOrNull((e) => e.id == modelAttribute?.fieldID);
      return getData(
        field!.variable,
        loop: loop,
        models: models,
        modelAttribute: modelAttribute?.subField,
      );
    case ModelListVar:
      final model = (variable as ModelListVar).models?[loop ?? 0] ??
          models?[(variable).modelID];
      assert(model != null, 'Model not found');
      final field = model!.fields
          .firstWhereOrNull((e) => e.id == modelAttribute?.fieldID);
      return getData(
        field!.variable,
        loop: loop,
        models: models,
        modelAttribute: modelAttribute?.subField,
      );
  }
}