shapeString function

String shapeString(
  1. String s, {
  2. int? maxLength,
  3. String ellipsis = '...',
})

Trims s and truncates to maxLength with optional ellipsis.

Implementation

String shapeString(String s, {int? maxLength, String ellipsis = '...'}) {
  String out = s.trim();
  if (maxLength != null && out.length > maxLength) {
    final int trimEnd = (maxLength - ellipsis.length).clamp(0, out.length);
    out = out.replaceRange(trimEnd, out.length, ellipsis);
  }
  return out;
}