truncate method

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

Returns the string truncated to a specified length, optionally adding ellipsis.

Implementation

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