maxLength method

String maxLength({
  1. required int max,
})

Cuts to max characters with "..." at the end. "Hello world".maxLength(max: 8) → "Hello..."

Implementation

String maxLength({required int max}) {
  if (length <= max) return this;
  if (max <= 3) return substring(0, max);
  return "${substring(0, max - 3)}...";
}