abbreviate method
使用点缩写字符串
Implementation
String? abbreviate(String? str, int maxWidth, {int offset = 0}) {
if (str == null) {
return null;
} else if (str.length <= maxWidth) {
return str;
} else if (offset < 3) {
return '${str.substring(offset, (offset + maxWidth) - 3)}...';
} else if (maxWidth - offset < 3) {
return '...${str.substring(offset, (offset + maxWidth) - 3)}';
}
return '...${str.substring(offset, (offset + maxWidth) - 6)}...';
}