有没有办法将堆栈子项自动调整为最大的兄弟?也就是说,如果我有Stack一个ListTile和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'))
],
)
Run Code Online (Sandbox Code Playgroud)
我试图使它一起工作Row,Column和Expanded而正在运行与无边界约束的问题.
有没有办法将Container(或任何其他小部件,如a GestureDetector)的大小调整为堆栈中最大的兄弟?
小智 26
我有同样的问题,最后设法用这个答案来解决它:
在Stack中,你应该将你的背景小部件包装在Positioned.fill中.
Run Code Online (Sandbox Code Playgroud)return new Stack( children: <Widget>[ new Positioned.fill( child: background, ), foreground, ], );
将其应用于您的问题会产生以下结果:
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')),
),
],
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2847 次 |
| 最近记录: |