The equivalent of wrap_content and match_parent in flutter?

Faisal Abid picture Faisal Abid · Feb 15, 2017 · Viewed 117.9k times · Source

In Android match_parent and wrap_content are used to resize the widgets automatically relative to their parent to the content the widget contains.

In Flutter it seems by default all widgets are set to wrap_content, how would I change it such that I can fill its width and height to that of its parent?

Answer

sourav pandit picture sourav pandit · May 8, 2019

You can do with little Trick: Suppose you have requirement of : ( Width,Height )

Wrap_content ,Wrap_content :

 //use this as child
 Wrap(
  children: <Widget>[*your_child*])

Match_parent,Match_parent:

 //use this as child
Container(
        height: double.infinity,
    width: double.infinity,child:*your_child*)

Match_parent,Wrap_content :

 //use this as child
Row(
  mainAxisSize: MainAxisSize.max,
  children: <Widget>[*your_child*],
);

Wrap_content ,Match_parent:

 //use this as child
Column(
  mainAxisSize: MainAxisSize.max,
  children: <Widget>[your_child],
);