limitTextLength static method

String? limitTextLength(
  1. String? text,
  2. int length, {
  3. String endString = '...',
})

Implementation

static String? limitTextLength(String? text, int length, {String endString = '...'}) {
  if (text == null) {
    return null;
  }

  if (text.length > length) {
    return '${text.substring(0, length)}$endString';
  } else {
    return text;
  }
}