问题
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