truncate method
Trims the string to a maximum length, adding ... if truncated.
Example:
'Hello, this is a long text'.truncate(10); // Output: 'Hello, thi...'
Implementation
String truncate(int maxLength) {
if (length <= maxLength) return this;
return '${substring(0, maxLength)}...';
}