valueTransformer function Null safety

dynamic valueTransformer(
  1. EComponentType componentType,
  2. dynamic value,
  3. QUFormComponentOptionsModel? componentOptions
)

Implementation

valueTransformer(EComponentType componentType, dynamic value,
    QUFormComponentOptionsModel? componentOptions) {
  switch (componentType) {
    case EComponentType.SLIDER:
    case EComponentType.RATE:
      try {
        return (value ?? 0).toDouble();
      } catch (e) {
        return 0.0;
      }
    case EComponentType.RADIO:
      try {
        return value['value'];
      } catch (e) {
        return value;
      }
    case EComponentType.SELECT:
      return componentOptions?.mode == 'multiple'
          ? ((value ?? []) as List)
              .map((e) => e is QUFormSelectOptionModel
                  ? e
                  : QUFormSelectOptionModel.fromJson(e))
              .toList()
          : value == null
              ? null
              : value is QUFormSelectOptionModel
                  ? value
                  : QUFormSelectOptionModel.fromJson(value);
    case EComponentType.SUBFORM:
      return ((value ?? []) as List)
          .map((e) => e is int ? e : int.parse(e))
          .toList();
    default:
      return value;
  }
}