toValue method

T toValue(
  1. Object? value
)

Converts a value to T.

Implementation

T toValue(Object? value) {
  if (value is T) {
    return value;
  } else if (T == num) {
    return parseNum(value) as T;
  } else if (T == int) {
    return parseInt(value) as T;
  } else if (T == double) {
    return parseDouble(value) as T;
  } else if (T == DateTime) {
    if (value is DateTime) return value as T;
    var ms = parseInt(value)!;
    return DateTime.fromMillisecondsSinceEpoch(ms) as T;
  } else {
    throw StateError("Can't convert type to $T: $value");
  }
}