【问题标题】:fittedbox with maximum two lines in flutter颤振中最多有两条线的装配箱
【发布时间】:2021-04-25 14:08:08
【问题描述】:
Container(
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 60),
        child: Text(
          //  subCategoryName,
          "This is a very Long Text takes more space",
          textAlign: TextAlign.center,
          maxLines: 2,
          overflow: TextOverflow.fade,
          style: Theme.of(context)
              .textTheme
              .headline3
              .copyWith(color: Colors.white, fontSize: 32),
        ),
      ),
    ),

Look this Picture

如果文本变得更长,我需要此行最多为两行,并像 FittedBox(使用 BoxFit.fitWidth)一样缩小尺寸

当我使用 FittedBox 时,它看起来像 like this。但如果需要,我需要将它增加到 2 行。任何解决方案都值得赞赏

【问题讨论】:

标签: flutter fitted-box


【解决方案1】:

得到了 Sam Chan 的回复。 我使用了AutoSizeText

【讨论】:

    【解决方案2】:

    如果您不想添加包,这里有解决方法。您可以检查文本的长度,并据此进行处理。

    // declare a widget
        Widget titleTextWidget = Text(
          title,
          style: TextStyle(
            fontWeight: FontWeight.w600,
          ),
          maxLines: 2,
          textAlign: TextAlign.center,
        );
    
    // use condition to render it.
        title.length > 45
            ? FittedBox(
                child: titleTextWidget,
              )
            : titleTextWidget,
    

    【讨论】:

      猜你喜欢
      • 2019-11-05
      • 2020-04-13
      • 1970-01-01
      • 2021-05-05
      • 2019-12-20
      • 2020-10-12
      • 2019-07-10
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多