【问题标题】:How to autosizing TextWidget in Flutter如何在 Flutter 中自动调整 Text Widget 的大小
【发布时间】:2018-03-10 23:43:12
【问题描述】:

我想在 Flutter 中将 auto-size 设置为 TextWidget

就像 自动调整 TextViews |安卓开发者https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview.html

Flutter 支持吗? TextWidget 如何实现自动调整大小?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您可以在 Fexible Widget 中添加您的 TextWidget。 Flexible Widget 会自动为其子级提供可用空间。

    【讨论】:

    • 但是如果我们给一个像 1000 这样的文本大小,那么它会溢出 Expanded 小部件,这只会破坏AutoResizeTextView的目的
    【解决方案2】:

    我可以使用FittedBox 来实现它。

    new FittedBox(
        fit: BoxFit.contain,
        child: new Padding(
            padding: const EdgeInsets.all(8.0),
            child: new Text(
                'LooooooooooooooooooooooooooooooooooooooooooooongText',
            ),
        ),
    ),
    

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 2022-11-22
      • 1970-01-01
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2022-08-04
      • 2018-11-17
      相关资源
      最近更新 更多