getDbValue static method

dynamic getDbValue(
  1. dynamic value
)

Get db value of some dart native value.

Implementation

static getDbValue(dynamic value) {
  var type = value.runtimeType;
  if (type == bool) {
    return value == null
        ? null
        : value
            ? 1
            : 0;
  }

  if (type == DateTime) {
    return value?.millisecondsSinceEpoch;
  }

  if (type == Color) return value == null ? null : (value as Color).value;

  if (value is Map) return json.encode(value);
  if (value is List) return json.encode(value);

  return value;
}