takeLeft method
Returns the leftmost characterCount characters of this string.
If the string length is less than or equal to characterCount, returns the entire string.
When addEllipses is true, appends '...' to the truncated string.
Example:
'Hello World'.takeLeft(5); // returns: 'Hello'
'Hello World'.takeLeft(5, addEllipses: true); // returns: 'Hello...'
Implementation
String takeLeft(int characterCount, {bool addEllipses = false}) {
if (length <= characterCount) {
return this;
}
String sub = substring(0, characterCount);
return addEllipses ? '$sub...' : sub;
}