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

查看:231
本文介绍了如何在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,
      ),
    ),
);

尽管用户输入文本位于我的父容器中居中,但提示文本却没有(顶部的空间比底部的空间大).有没有办法使提示文本垂直居中?

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...,这对用户而言不是很友好. (因此,是否可以在hintText中使用换行符?)

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天全站免登陆