How to expand to Parent Widget width?
Published in
1 min readJul 29, 2020
This is always asked by the people, how to extend widget to its parent, so I thought of writing one blog which has all this.
The correct solution would be to use the SizedBox.expand
widget, which enforces its child
to match its parent's size.
SizedBox.expand(
child: RaisedButton(...),
)
Using SizeBox
SizedBox(
width: double.infinity,
// height: double.infinity,
child: RaisedButton(...),
)
Using ConstrainedBox
ConstrainedBox(
constraints: const BoxConstraints(minWidth: double.infinity),
child: RaisedButton(...),
)
Using Container
Container
should be used when we required other properties of it, otherwise, we should avoid and use SizeBox
Container(
width: double.infinity,
// height: double.infinity,
child: RaisedButton(...),
)