checkValueType function

Object? checkValueType(
  1. Object? value,
  2. Object? defaultValue
)

Implementation

Object? checkValueType(Object? value, Object? defaultValue) {
  if (value.runtimeType == defaultValue.runtimeType) {
    return value;
  }

  if (value is num && defaultValue is num) {
    if (defaultValue is double) {
      return value.toDouble();
    } else if (defaultValue is int) {
      return value.toInt();
    }
  }

  if (defaultValue is String) {
    return value.toString();
  }

  if (defaultValue == null) {
    return value;
  }

  return null;
}