magicString method
Converts the value to a String.
defaultValue: The value to return if the conversion fails or the value isnull.nonEmptyInDebug: Iftrue, returns 'Lorem Ipsum' when thedefaultValueis empty and the app is in debug mode.
Implementation
String magicString({String defaultValue = '', bool nonEmptyInDebug = false}) {
if (isNull) {
return defaultValue.validString(
defaultValue: defaultValue,
nonEmptyInDebug: nonEmptyInDebug,
);
}
if (this is String) {
return (this as String).validString(
defaultValue: defaultValue,
nonEmptyInDebug: nonEmptyInDebug,
);
}
if (this is num) return toString();
if (this is bool) return (this as bool) ? 'true' : 'false';
if (this is List) return (this as List).join(', ');
if (this is Map) {
return (this as Map).entries
.map((e) => '${e.key}: ${e.value}')
.join(', ');
}
if (this is Set) return (this as Set).join(', ');
if (this is Queue) return (this as Queue).join(', ');
if (this is DateTime) return (this as DateTime).toIso8601String();
return defaultValue.validString(
defaultValue: defaultValue,
nonEmptyInDebug: nonEmptyInDebug,
);
}