truncateWords method
Truncates at a word boundary instead of mid-word.
Implementation
String truncateWords(int maxLength, {String ellipsis = '...'}) {
if (length <= maxLength) return this;
final cut = substring(0, maxLength - ellipsis.length);
final lastSpace = cut.lastIndexOf(' ');
return (lastSpace > 0 ? cut.substring(0, lastSpace) : cut) + ellipsis;
}