将容器高度设置为 40 时,Flutter TextField 提示或文本未居中对齐

问题描述 投票:0回答:1

我在

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
(对齐问题)时:

flutter mobile alignment
1个回答
0
投票

您可以使用

isDense: true
,它会适应高度。

decoration: InputDecoration(
  contentPadding: EdgeInsets.only(left: 16),
  hintText: 'Enter your text',
  isDense: true,
© www.soinside.com 2019 - 2024. All rights reserved.