parser method

  1. @override
T? parser(
  1. covariant Object? unparsedValue
)
override

Parses a value into an instance of T.

Implementation

@override
T? parser(Object? unparsedValue) {
  if (unparsedValue.runtimeType == String) {
    unparsedValue = num.tryParse(unparsedValue as String);
  }

  final num? unparsedValueAsNum = unparsedValue as num?;

  if (T == int) {
    return unparsedValueAsNum?.toInt() as T?;
  } else if (T == double) {
    return unparsedValueAsNum?.toDouble() as T?;
  }

  return unparsedValueAsNum as T?;
}