首页 > 解决方案 > 在 Flutter Text Widget 中调整新的行距

问题描述

所以,目标很简单,将一堆文本包装在一个容器中。为此,我遵循了这个Flutter-wrapping text,但是创建的新行在前一行之间有太多空间

我的 Container() 和 Text() 代码:

 description == ""
              ? SizedBox.shrink()
              : Container(
                  padding: const EdgeInsets.symmetric(horizontal: 10.0),
                  //width: MediaQuery.of(context).size.width * 0.8,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      new Text(
                        description,
                        textAlign: TextAlign.left,
                        style: TextStyle(fontSize: 18),
                      ),
                    ],
                  ),
                )

小提示:如果给 Parent 小部件提供了任何描述,我只是使用 SizeBox.shrink() 作为“空小部件”。

当前情况如何,空间太大:

当前的

应该如何:

设计目标

我知道 1º 图像更大,但这不是行距更大的原因

标签: fluttertextflutter-layouttext-widget

解决方案


这里提到。height您可以通过更改样式内部的属性来调整行距。1.0对我来说似乎很好,但您可以尝试将其设置为0.80.7

  Container(
                  padding: const EdgeInsets.symmetric(horizontal: 10.0),
                  //width: MediaQuery.of(context).size.width * 0.8,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      new Text(
                        'You have pushed the button this many times: You have pushed the button this many times: You have pushed the button this many times: You have pushed the button this many times: You have pushed the button this many times: You have pushed the button this many times: You have pushed the button this many times:',
                        textAlign: TextAlign.left,
                        
                        style: TextStyle(fontSize: 18,   height: 1.0 ),
                      ),
                    ],
                  ),),

推荐阅读