overflow: TextOverflow.ellipsis, 缺陷:会将长字母、数字串整体显示省略
现象:分组用户1234567890123456789,可能会显示成:分组用户...
解决办法:将每个字符串之间插入零宽空格
String breakWord(String word){
if(word == null || word.isEmpty){
return word;
}
String breakWord = ' ';
word.runes.forEach((element){
breakWord += String.fromCharCode(element);
breakWord +='\u200B';
});
return breakWord;
}
直接调用
Text(
breakWord('用户01234567890123456789'),
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
本文介绍了一种解决UI中长字符串显示不全的方法,通过在字符串之间插入零宽空格,实现长字符串的优雅折行,避免了使用省略号整体截断的问题。
25

被折叠的 条评论
为什么被折叠?



