flutter overflow 属性省略号解决数字、长字母串整体显示省略号问题

overflow: TextOverflow.ellipsis,
缺陷: 会将长字母、数字串整体显示省略
现象: 分组-12333333333333333333333333,可能会显示成:分组-1…

解决办法: 将每个字符串之间插入零宽空格

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;
}

调用:

child: Text(
  breakWord(text),
  style: TextStyle(
      fontSize: 14,
      color: selected ? TriColor.PRIMARY : TriColor.BLACK),
  maxLines: 1,

  overflow: TextOverflow.ellipsis,
),

猜你喜欢

转载自blog.csdn.net/lxd_love_lgc/article/details/106998524