Is there a way to size a stack child automatically to its largest sibling? I.e. if I have a Stack
with a ListTile
and a Container
on top, how do I make sure the Container
covers the entire ListTile
?
Example:
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')) ], )
I tried to make it work with Row
, Column
and Expanded
but am running into problems with unbounded constraints.
Is there a way to size the Container
(or any other widget such as a GestureDetector
) to its largest sibling in the stack?
StackFit fit. How to size the non-positioned children in the stack. The constraints passed into the Stack from its parent are either loosened (StackFit. loose) or tightened to their biggest size (StackFit. expand).
The container in Flutter is a parent widget that can contain multiple child widgets and manage them efficiently through width, height, padding, background color, etc. It is a widget that combines common painting, positioning, and sizing of the child widgets.
A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been allocated to that stack.
I had the same issue and finally managed to solve it using this answer:
Inside your Stack, you should wrap your background widget in a Positioned.fill.
return new Stack( children: <Widget>[ new Positioned.fill( child: background, ), foreground, ], );
-- Mary, https://stackoverflow.com/a/45745479
Applying that to your question results in the following:
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')), ), ], ),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With