getValueFromDbValue static method

dynamic getValueFromDbValue(
  1. Type type,
  2. dynamic dbValue
)

Get dart native value of some db value.

Implementation

static getValueFromDbValue(Type type, dynamic dbValue) {
  if (type == bool) return dbValue == null ? null : dbValue == 1;

  if (type == double && dbValue is int) return dbValue.toDouble();
  if (type == double && dbValue is String) return double.tryParse(dbValue);

  if (type == DateTime) {
    return dbValue == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(dbValue);
  }

  if (type == Color) return dbValue == null ? null : Color(dbValue);
  if (type == Map) return dbValue == null ? null : json.decode(dbValue);
  if (type == List) return dbValue == null ? null : json.decode(dbValue);
  return dbValue;
}