maybeParseValue<T> static method
T?
maybeParseValue<T>(
- dynamic input
Attempts to parse the given input
into the type T
. This currently
supports the following types:
bool
String
double
int
num
DateTime
Duration
Any other type will result in an exception.
Implementation
static T? maybeParseValue<T>(dynamic input) {
dynamic result;
if (T == bool) {
result = maybeParseBool(input);
} else if (T == String) {
result = input?.toString();
} else if (T == double) {
result = maybeParseDouble(input);
} else if (T == int) {
result = maybeParseInt(input);
} else if (T == num) {
result = maybeParseDouble(input);
} else if (T == DateTime) {
result = maybeParseDateTime(input);
} else if (T == Duration) {
result = maybeParseDurationFromMillis(input);
} else {
throw Exception('Unknown value type: [${T.runtimeType}]');
}
return result as T?;
}