首页 > 解决方案 > 如何在颤动中同时换行和缩小文本?

问题描述

我在圆形容器中有一个文本,该文本来自 API。所以我无法控制文本的长度。我通过使用 FittedBox 缩小它来显示容器内的文本,不管它有多长。

             Container(
                        height: 44,
                        width: 44,
                        padding: EdgeInsets.all(3),
                        alignment: Alignment.center,
                        child: Row(
                          children: [
                            Flexible(
                              child: FittedBox(
                                child: Text('Best Seller'),
                              ),
                            ),
                          ],
                        ),
                        decoration: BoxDecoration(shape: BoxShape.circle, color: Color(0xFFF37C43)),
                      )

我的问题是如何在新行中显示文本的所有单词,同时缩小它们。我正在考虑使用 Column 并从文本的每个单词生成子小部件。但这似乎不是很直观。如果需要,我愿意更改我的布局设计。

标签: flutterdartflutter-layout

解决方案


使用自动大小文本。这是链接 https://pub.dev/packages/auto_size_text


推荐阅读