truncate method

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

Truncates the string safely.

Example:

"Hello World".truncate(5); // "Hello..."

Implementation

String truncate(int maxLength, {String suffix = '...'}) {
  if (this == null) return '';
  if (this!.length <= maxLength) return this!;
  return this!.substring(0, maxLength) + suffix;
}