gpt4 book ai didi

flutter - 如何更改 TextField 的高度和宽度?

转载 作者:IT老高 更新时间:2023-10-28 12:29:15 69 4
gpt4 key购买 nike

如何自定义TextFieldwidthheight

最佳答案

要调整宽度,您可以用 SizedBox 小部件包裹您的 TextField,如下所示:

const SizedBox(
width: 100.0,
child: TextField(),
)

对于 TextField 的高度,我不太确定您想要的是什么,但您肯定可以看看 TextStyle 小部件,其中您可以操纵 fontSize 和/或 height

const SizedBox(
width: 100.0,
child: TextField(
style: TextStyle(fontSize: 40.0, height: 2.0, color: Colors.black),
),
)

请记住,根据属性本身的注释,TextStyle 中的 height 是字体大小的倍数:

The height of this text span, as a multiple of the font size.

When [height] is null or omitted, the line height will be determinedby the font's metrics directly, which may differ from the fontSize.When [height] is non-null, the line height of the span of text will be amultiple of [fontSize] and be exactly fontSize * height logical pixelstall.

最后但同样重要的是,您可能想看看 TextFielddecoration 属性,它为您提供了很多可能性

编辑: 如何更改 TextField

的内部填充/边距

您可以使用 InputDecorationTextFielddecoration 属性。例如,您可以这样做:

const TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 40.0),
),
)

关于flutter - 如何更改 TextField 的高度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50400529/

69 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com