【问题标题】:Flutter Text overflow颤振文本溢出
【发布时间】:2021-06-06 01:39:46
【问题描述】:

如果不知道框的 const 宽度,如何控制 TextOverFlow。 我知道

Text(
      'some Text',
      overflow: TextOverflow.ellipsis,
)

但是有没有办法包装小部件,例如扩展或灵活?

【问题讨论】:

  • 我想你已经说明了解决方案本身,它使用Flexibleoverflow 属性来控制文本溢出。如果您能澄清阻止您使用这些小部件的问题、出了什么问题或是否出现任何错误,那就更好了。
  • @Bach 没错,但它不适用于 Flexible,为此,我需要将它包装在一个容器中并再次赋予它宽度。
  • @AliAzimoshan 感谢您澄清阿里。您能否给我们更多关于您当前实现Flexible 的代码,也许是包含它的屏幕?更容易查明问题

标签: flutter flutter-layout flutter-text


【解决方案1】:
FittedBox(
      fit: setToWidth ? BoxFit.contain : BoxFit.none,
      child: Text(
        displayText,
        maxLines: 2,
        textAlign: textAlign,
        style: setToWidth
            ? TextStyle(
                fontWeight: fontWeight,
                color: textColor,
                fontFamily: AppFonts.circularStd,
              )
            : TextStyle(
                fontWeight: fontWeight,
                color: textColor,
                fontFamily: AppFonts.circularStd,
                fontSize: textSize),
      ),
    );

试试这个

【讨论】:

    【解决方案2】:

    您可以尝试使用 AutoSizeText。 https://pub.dev/packages/auto_size_text

    注意:它会增加您的整体应用程序大小,因为它需要外部依赖项。但它会为您提供一些额外的功能,例如 maxLines 和 minLines。我会建议阅读更多相关信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-22
      • 2021-06-06
      • 2020-09-30
      • 1970-01-01
      • 2020-09-04
      • 2020-11-13
      • 2021-09-28
      • 2020-07-23
      相关资源
      最近更新 更多