trunc method

String trunc([
  1. int max = 20
])

Truncates the string to a maximum of max characters and adds "..." if needed.

Implementation

String trunc([int max = 20]) {
  String out = this;
  return out.length > max ? "${out.substring(0, max - 3)}..." : out;
}