tryParse static method

DataSchemaValue? tryParse(
  1. dynamic value
)

Tries to instantiate a DataSchemaValue from a raw value.

If the value is a non-valid data type, the method returns null instead.

Implementation

static DataSchemaValue? tryParse(dynamic value) {
  if (value == null) {
    return const NullValue._create();
  }

  if (value is bool) {
    return BooleanValue._fromValue(value);
  }

  if (value is String) {
    return StringValue._fromValue(value);
  }

  if (value is int) {
    return IntegerValue._fromValue(value);
  }

  if (value is double) {
    return NumberValue._fromValue(value);
  }

  if (value is List<Object?>) {
    return ArrayValue.tryParse(value);
  }

  if (value is Map<Object?, Object?>) {
    return ObjectValue.tryParse(value);
  }

  return null;
}