flutter - 如何在 TextField 中垂直居中不同大小的 hintText?

标签 flutter dart flutter-layout

我有一个像这样的 TextField,其中输入文本和提示文本的大小不同。

TextField(
    style: Theme.of(context).textTheme.subhead.copyWith(
      fontSize: 70.0,
    ),
    decoration: InputDecoration(
      hintText: 'Enter a number',
      hideDivider: true,
      hintStyle: TextStyle(
        color: Colors.grey[500],
        fontSize: 25.0,
      ),
    ),
);

虽然用户输入文本在我的父容器中居中,但 hintText 不是(顶部比底部有更多空间)。有没有办法让提示文本也垂直居中?

提示文本与输入文本大小不同的原因是它占用的空间比绿色 Container 多,所以它看起来像 Enter a nu...,这是非常人性化。 (或者,有没有办法在 hintText 中换行?)

Hint text is smaller so that I can fit it all in the widget

Input text is centered

最佳答案

我看到这已经超过 2 年了,但以防其他人遇到这个问题:

InputDecoration 具有属性 contentPadding。

TextField(
  decoration: InputDecoration(
    hintText: 'Hint Text',
    contentPadding: EdgeInsets.all(10.0),
  ),
);

关于flutter - 如何在 TextField 中垂直居中不同大小的 hintText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47340980/

相关文章:

firebase - 未处理的异常 : NoSuchMethodError: The method 'split' was called on null

firebase - 为什么我的快照显示它包含数据?

flutter - 在 flutter 中带有渐变边框的轮廓透明按钮

json - Flutter - 无法将所有 json 数据从 api 响应保存到 Iterable List 编辑 : ( Can't Fetch Data from iterable List)

Flutter - 'the property ' 设置'无法无条件访问,因为接收器可以是 'null' '

flutter - 如何在一列内实现多个水平列表

android - 在 Flutter 中按下后退按钮时关闭抽屉导航

android - 如何在 Flutter 中使用设备的默认字体?

mysql - Flutter SQFLite Assets 数据库

dart - 将方法作为参数传递给小部件