truncate method

String truncate(
  1. int maxLength, {
  2. String ellipsis = '...',
})

Truncates to maxLength chars, appending ellipsis if cut.

'Hello World'.truncate(7); // 'Hell...'

Implementation

String truncate(int maxLength, {String ellipsis = '...'}) {
  _checkTruncationLength(maxLength, ellipsis);
  if (length <= maxLength) return this;
  return substring(0, maxLength - ellipsis.length) + ellipsis;
}