How to vertically center differently-sized hintText in Flutter TextField?

喜夏-厌秋 提交于 2019-12-10 23:54:56

问题


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

new TextField(
    style: Theme.of(context).textTheme.subhead.copyWith(
      fontSize: 70.0,
    ),
    decoration: new InputDecoration(
      hintText: 'Enter a number',
      hideDivider: true,
      hintStyle: new 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? 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?)


回答1:


new TextField(
  decoration: new InputDecoration(
    hintText: 'your hint',
  ),
  textAlign: TextAlign.center,
)

textAlign: TextAlign.center will make your hint appear in the center.



来源:https://stackoverflow.com/questions/47340980/how-to-vertically-center-differently-sized-hinttext-in-flutter-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!