【发布时间】:2020-06-15 12:57:06
【问题描述】:
我正在尝试创建一个 40 像素高的 TextField,并以圆角矩形作为背景。不敢相信似乎没有一种直接的方法可以做到这一点。
这是我尝试过的:
- 在
Container父级中设置高度。不起作用,孩子将自己画在父母的边界上。 - 设置
expands: true,这需要maxLines: null。请参阅下面的代码。这可行,但我想将行数限制为 1。
Container(
decoration: BoxDecoration(
color: Color(0xfff0f0f0),
borderRadius: BorderRadius.circular(5),
),
height: 40,
child: TextField(
style: TextStyle(fontSize: 18),
expands: true,
maxLines: null,
decoration: InputDecoration(
contentPadding:
EdgeInsets.all(8),
border: InputBorder.none,
isDense: true,
),
))
【问题讨论】:
-
你试过设置
minLines: 1,吗? -
如果
expands: true,则必须为null。 -
尝试使用
sizedBox,它会强制调整其子项的大小。 api.flutter.dev/flutter/widgets/SizedBox-class.html -
也不起作用。我找到了解决方法,请参阅我的答案。
标签: flutter