如何自定义TextField
的width
和height
?
最佳答案
要调整宽度,您可以用 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 determined by 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 a multiple of [fontSize] and be exactly
fontSize * height
logical pixels tall.
最后但同样重要的是,您可能想看看 TextField
的 decoration
属性,它为您提供了很多可能性
编辑: 如何更改 TextField
您可以使用 InputDecoration
和 TextField
的 decoration
属性。例如,您可以这样做:
const TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 40.0),
),
)
https://stackoverflow.com/questions/50400529/