有没有办法自动将堆栈子级的大小调整为其最大的兄弟级?
IE。如果我有一个Stack
with a ListTile
and a Container
最上面,我如何确保Container
覆盖整个ListTile
?
例子:
new Stack(children: <Widget>[
new ListTile(
leading: new AssetImage('foo.jpg'),
title: new Text('Bar'),
subtitle: new Text('yipeee'),
isThreeLine: true,
),
new Container(color: Colors.grey, child: new Text('foo'))
],
)
我试图让它与Row
, Column
and Expanded
但我遇到了无限约束的问题。
有没有办法调整大小Container
(或任何其他小部件,例如GestureDetector
)到堆栈中最大的同级?
我遇到了同样的问题,最终使用这个答案解决了它:
在 Stack 中,您应该将背景小部件包装在 Positioned.fill 中。
return new Stack(
children: <Widget>[
new Positioned.fill(
child: background,
),
foreground,
],
);
-- Mary https://stackoverflow.com/users/8468400/mary, https://stackoverflow.com/a/45745479 https://stackoverflow.com/a/45745479
将其应用于您的问题会产生以下结果:
Stack(
children: <Widget>[
ListTile(
leading: AssetImage('foo.jpg'),
title: Text('Bar'),
subtitle: Text('yipeee'),
isThreeLine: true,
),
Positioned.fill(
child: Container(color: Colors.grey, child: Text('foo')),
),
],
),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)