我有一个非常简单的TextField
,其中有textAlign:TextAlign.center
(如其他答案中所建议的那样)。
但是,提示文本不是水平居中的,而输入文本是居中的。 (见附图)
我想知道为什么..请有人帮忙。
代码:
Container(
margin: EdgeInsets.symmetric(horizontal: 18.0),
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'time',
),
),
width: 80,
)
最佳答案
您必须使用hintText而不是labelText:
Container(
margin: EdgeInsets.symmetric(horizontal: 18.0),
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'time', //instead of labelText
),
),
width: 80,
)
关于Flutter TextField 提示文本未水平居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64537733/