limit method
String with length
to limit the number of characters.
If the string is restricted, suffix
is added at the end.
Stringをlength
で文字数を制限します。
文字列が制限された場合、最後尾に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";
}