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

如何自定义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 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.

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

编辑: 如何更改 TextField

的内部填充/边距

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

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

https://stackoverflow.com/questions/50400529/

相关文章:

dart - 错误 : Only static members can be accessed in

flutter - 在 Flutter 中显示用户友好的错误页面而不是异常

dart - 如何在 Flutter 中隐藏 TextField 底部的字母计数器

android - 如何在 flutter 中制作不透明的教程屏幕?

dart - flutter : Where is the title of Material Ap

dart - 为什么 setState 会关闭?

dart - 如何强制 Flutter 重建/重绘所有小部件?

android - 让 Flutter 应用全屏显示

flutter - 点击 AppBar 打开抽屉

flutter - 在 Flutter 中更改 TextField 的下划线