首页 > 解决方案 > 设置溢出 TextOverflow.ellipsis 文本长度 Flutter

问题描述

如何设置溢出的长度:TextOverflow.ellipsis 因为它截断了您在 img 中看到的文本。文本“这是第一个......”和数字“#1520”之间有一个空格。溢出会截断“第一个...”单词之后的文本。

我希望“现在卡”字样将显示在行中。怎么解决?,谢谢

 Container(
      color: Colors.grey,
      child: ListTile(
        title: Container(
          child: Row(
             mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
             Flexible(child: Text('This is the first card now its time sad sad sad sads ad sdsadsads dsa dsad asdasdasd', overflow: TextOverflow.ellipsis,  style: TextStyle(color: Colors.white),)),
               
              Flexible(child: Text('#1520',  overflow: TextOverflow.ellipsis, style: TextStyle(color: Colors.white),)),
            ],
          ),
        ),
      ),
    ),

在此处输入图像描述

我不希望我的所有文字都可见,我只想在一行中显示一些单词。如果您查看 img,您会看到文本和 #1520 之间有一个空白区域。我想使用溢出显示:这是现在的第一张卡片.. #1520

标签: flutteroverflow

解决方案


  1. 如果您希望所有文本都可见,只需从文本小部件中删除溢出属性。
  2. 如果要将文本限制为某些行,请添加带有溢出的 maxLines 属性。像这样
child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Flexible(child: Text("This is the first card now its time sad sad sad sads ad sdsadsads dsa dsad asdasdasd", maxLines: 2, overflow: TextOverflow.ellipsis,)),
                  Flexible(child: Text("#1520"))
                ],
              ),

推荐阅读