调整 Flutter Text Widget 中的新行间距

Mar*_*ira 3 text text-widget flutter flutter-layout

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

\n

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

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

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

\n

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

\n

当前的

\n

应该如何:

\n

设计目标

\n

我知道 1\xc2\xba 图像更大,但这不是行间距更大的原因

\n

Kri*_*ali 5

正如从这里提到的。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 ),
                      ),
                    ],
                  ),),
Run Code Online (Sandbox Code Playgroud)

  • 令人遗憾的是,它通常调整文本高度,而不仅仅是换行文本行之间的间距,其中文本是单个小部件。 (4认同)