【问题标题】:How to make the Text take all the space in the container [duplicate]如何使文本占用容器中的所有空间[重复]
【发布时间】:2021-06-26 08:18:40
【问题描述】:

在上图中, 如果使用 FittedBox,则文本仅在水平形状中对齐和调整大小。

如果不使用 FittedBox 则文本从容器中流出

如何动态改变文字大小,让文字占据所有可用空间

Container(
                  margin: EdgeInsets.all(10),
                  width: double.infinity,
                  height: MediaQuery.of(context).size.height * 0.6,
                  child: FittedBox(
                    child: Text(
                      "Click Here Click Here Click Here Click Here Click Here Click Here Click Here ",
                      overflow: TextOverflow.ellipsis,
                      
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        fontSize: 60,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  decoration: BoxDecoration(
                    color: Colors.orange,
                    borderRadius: BorderRadius.circular(20),
                  ),
                ),

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    你已经给容器无限的宽度,你应该给它一个宽度,然后文本组件会自动换行。

    Container(
    width: MediaQuery.of(context).size.width,
    ...
    

    【讨论】:

    • 给定宽度后还是一样,我给了宽度100,文本仍然在一行中
    猜你喜欢
    • 1970-01-01
    • 2018-02-07
    • 2021-01-23
    • 1970-01-01
    • 2018-04-23
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多