truncate method

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

Shortens the string to a specified length with an optional ellipsis.

Implementation

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