flatString function
- dynamic value
Converts a dynamic value to a flat string representation.
- If the value is null, an empty string is returned.
- If the value is a number, it is converted to a string.
- If the value is a DateTime object, it is formatted as a string.
- If the value is a boolean, it is converted to a string.
- If the value is a Map or an Iterable, the values are joined with a comma.
The resulting string is then processed to remove diacritics, convert to lowercase, and remove leading/trailing whitespace.
Returns the flat string representation of the value.
Implementation
String flatString(dynamic value) {
if (value == null) return '';
if (value is num) value = value.toString();
if (value is DateTime) value = value.format();
if (value is bool) value = value.toString();
if (value is Color) value = value.hexadecimal;
if (value is Widget) value = value.text;
if (value is Map) value = value.values.join(", ");
if (value is Iterable) value = value.join(", ");
return "$value".removeDiacritics.toLowerCase().trimAll;
}