parseValue<T> method

  1. @override
T parseValue <T>(dynamic v)
override

Parses values coming from database into Dart values

Implementation

@override
T parseValue<T>(dynamic v) {
  if (T == String) {
    return v;
  } else if (T == int) {
    return v?.toInt();
  } else if (T == double) {
    return v?.toDouble();
  } else if (T == num) {
    return v;
  } else if (T == DateTime) {
    if (v == null) return null;
    if (v is String) return DateTime.parse(v) as T;
    if (v == int) return DateTime.fromMillisecondsSinceEpoch(v * 1000) as T;
    return null;
  } else if (T == bool) {
    if (v == null) return null;
    return (v == 0 ? false : true) as T;
  } else {
    throw new Exception("Invalid type $T!");
  }
}