mapToUse function
Converts an entity map into a map suitable for SQLite.
- Values still equal to a ColumnType enum are replaced with
null(so they can be stored as SQL NULL). - When
forDBis true (the default),boolvalues are coerced to0/1andDateTimevalues to their string representation.
Pass forDB: false when you want a plain Dart map (e.g. to serialize to
JSON or display it in the UI).
Implementation
Map<String, dynamic> mapToUse(
Map<String, dynamic> objectMap, {
bool forDB = true,
}) {
return objectMap.map((String key, dynamic value) {
if (value is ColumnType) return MapEntry(key, null);
if (forDB && value is bool) return MapEntry(key, value ? 1 : 0);
if (forDB && value is DateTime) return MapEntry(key, value.toString());
return MapEntry(key, value);
});
}