truncToLength method

String truncToLength(
  1. int length
)

Truncates the string to the given length and adds '...' at the end.

Implementation

String truncToLength(int length) {
  return (this.length > length
      ? '${this.substring(0, length).trim()}...'
      : this);
}