gpt4 book ai didi

flutter - 如何让 child 在 flutter 中连续适应高度?

转载 作者:行者123 更新时间:2023-12-05 08:30:34 24 4
gpt4 key购买 nike

我有一个带有输入文件和搜索按钮的 Row 小部件。该行位于一列内。

enter image description here

如何使搜索按钮适合行的高度,使按钮大小等于输入字段的高度?

我尝试将 crossAxisAlignment: CrossAxisAlignment.stretch, 添加到 Row 但出现错误:-

BoxConstraints 强制无限高。

我没有输入字段的高度。并且不想对按钮的高度进行硬编码,因为它应该始终与输入框的高度匹配。

此外,为行分配高度并添加 CrossAxisAlignment.stretch 不会更改输入字段的高度,唯一的按钮会发生变化。

这是什么问题,如何解决?

Row(
// crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Container(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'search',
hintStyle:
Theme.of(context).textTheme.bodyText2.copyWith(
color: Theme.of(context).accentColor,
),
contentPadding: EdgeInsets.symmetric(
vertical: 8, horizontal: 20
),
fillColor: Theme.of(context).primaryColor,
filled: true,
),
style: Theme.of(context).textTheme.bodyText2,
),
),
),
FlatButton(
onPressed: () {},
color: Colors.grey,
child: Icon(
Icons.search,
),
),
],
)

最佳答案

您可以将行包装在 IntrinsicHeight 中,RowcrossAxisAlignmentCrossAxisAlignment.strech。例如:

IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [TextField(..), TextButton(..)],
),
),

关于flutter - 如何让 child 在 flutter 中连续适应高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63507732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com