limit method

String limit(
  1. int length, {
  2. String suffix = "...",
})

String with length to limit the number of characters.

If the string is restricted, suffix is added at the end.

Stringlengthで文字数を制限します。

文字列が制限された場合、最後尾にsuffixが追加されます。

final text = "abcdefghijklmn";
final limited = text.limit(5); // "abcde..."

Implementation

String limit(int length, {String suffix = "..."}) {
  if (this.length <= length) {
    return this;
  }
  return "${substring(0, length)}$suffix";
}