我在
TextField
内部使用了Container
,宽度和高度固定。一旦我设置容器height:40
,然后TextField
提示文本和文本未居中对齐,但如果我设置容器height:50
,那么一切都会顺利。我也尝试过设置 fontSize 但仍然不起作用。我已经检查了这些问题:问题 1 、问题 2、问题 3,还尝试了一些其他代码,但在容器height:40
时不起作用。
这是我正在使用的代码:
Container(
width: 300,
height: 40,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.deepPurpleAccent,
),
child: TextFormField(
textAlign: TextAlign.left,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 16),
hintText: 'Enter your text',
border: InputBorder.none,
hintStyle: TextStyle(
color: Colors.white,
),
),
),
),
UI(输出)当
height:50
(完美)时:
UI(输出)当
height:40
(对齐问题)时:
您可以使用
isDense: true
,它会适应高度。
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 16),
hintText: 'Enter your text',
isDense: true,