truncateText static method

String truncateText(
  1. String text,
  2. int maxLength
)

Truncate a text to the specified maxLength and append '...' if it exceeds.

Implementation

static String truncateText(String text, int maxLength) {
  if (text.length <= maxLength) {
    return text;
  } else {
    return '${text.substring(0, maxLength)}...';
  }
}