How to resize widget based on parent widget in Flutter?

This Article is posted by seven.srikanth at 11/19/2022 1:58:53 AM



<p>Here is how you can resize the widget based on the parent widget in Flutter.</p> <p>Here is the outcome for this example.</p> <p>![](../../../Uploads/883b310f-d930-4a62-9d08-46793717b7c4.gifwidth="50%height="auto](</p> <p>You can achieve this using FractionalySizedBox. It is a widget that sizes its child to a fraction of the total available space.</p> <p id="4ec9b0;](MyApp());" color:="" color:=>color: #9cdcfe;](args) </p> <p id="9cdcfe;](key" color:= color:=>color: #569cd6;](class color: #4ec9b0;](MyApp color: #569cd6;](extends color: #4ec9b0;](StatelessWidget ); color: #9cdcfe;](@ color: #9cdcfe;](override</p> <p>color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext color: #9cdcfe;](context) { color: #c586c0;](return color: #569cd6;](const color: #4ec9b0;](MaterialApp( color: #9cdcfe;](home: color: #4ec9b0;](Scaffold( color: #9cdcfe;](body: color: #4ec9b0;](MyLayoutWidget(), ), ); } }</p> <p id="9cdcfe;](key," color:= color:="" color:="">color: #569cd6;](class color: #4ec9b0;](MyLayoutWidget color: #569cd6;](extends color: #4ec9b0;](StatelessWidget ); color: #9cdcfe;](@ color: #9cdcfe;](override</p> <p>color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext color: #9cdcfe;](context) { color: #c586c0;](return color: #4ec9b0;](Center( color: #9cdcfe;](child: color: #4ec9b0;](LayoutBuilder( color: #9cdcfe;](builder: (color: #9cdcfe;](p0, color: #9cdcfe;](p1) { color: #c586c0;](return color: #4ec9b0;](Container( color: #9cdcfe;](color: color: #4ec9b0;](Colors.color: #9cdcfe;](red, color: #9cdcfe;](height: color: #9cdcfe;](p1.color: #9cdcfe;](maxHeight / color: #b5cea8;](2, color: #9cdcfe;](width: color: #9cdcfe;](p1.color: #9cdcfe;](maxWidth / color: #b5cea8;](2, color: #9cdcfe;](child: color: #4ec9b0;](FractionallySizedBox( color: #9cdcfe;](alignment: color: #4ec9b0;](Alignment.color: #9cdcfe;](center, color: #9cdcfe;](widthFactor: color: #b5cea8;](0.5, color: #9cdcfe;](heightFactor: color: #b5cea8;](0.5, color: #9cdcfe;](child: color: #4ec9b0;](Container( color: #9cdcfe;](color: color: #4ec9b0;](Colors.color: #9cdcfe;](green, ), ), ); }, ), ); } } ` Thanks,Srikanth</p>


Tags: set height or width based on parent widget;








0 Comments
Login to comment.
Recent Comments