truncate method
Truncates this string to maxLength characters, appending ellipsis
if truncation occurs.
'Hello World'.truncate(7) // 'Hello W…'
Implementation
String truncate(int maxLength, {String ellipsis = '…'}) {
if (length <= maxLength) return this;
return '${substring(0, maxLength)}$ellipsis';
}