如何在TextField中垂直居中不同大小的hintText? [英] How to vertically center differently-sized hintText in TextField?

查看:17
本文介绍了如何在TextField中垂直居中不同大小的hintText?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a TextField like this, where the input text and the hint text are sized differently.

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 不是(顶部空间比底部空间大).有没有办法让提示文本也垂直居中?

While the user input text is centered in my parent container, the hintText is not (top has more space than the bottom). Is there a way to vertically center the hint text as well?

提示文本与输入文本大小不一样的原因是它比绿色Container占用的空间更多,所以看起来像Enter a nu...,也就是'不是很用户友好.(或者,有没有办法在提示文本中添加换行符?)

The reason the hint text is not the same size as the input text is that it takes up more space than the green Container has, so it looks like Enter a nu..., which isn't very user friendly. (So alternatively, is there a way to have a newline in the hintText?)

推荐答案

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

I see this is over 2 years old but in case others run into this problem:

InputDecoration 具有属性 contentPadding.

InputDecoration has the property contentPadding.

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

这篇关于如何在TextField中垂直居中不同大小的hintText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆