How to impose different constraints (height/width) on its child than it gets from its parent in Flutter?

This Article is posted by seven.srikanth at 11/22/2022 1:08:31 AM



<p>Let's see how to impose different constraints on its child than it gets from its parent.</p> <p>Below is an example of how it looks.</p> <p>![](../../../Uploads/eeba9ef4-1726-404d-a235-6d3e05842113.gifwidth="50%height="auto](</p> <p>You can achieve this in flutter using OverFlowBox widget. It is a widget that imposes different constraints (like height/width) on its child widget than it gets from its parent widget, possibly allowing the child to overflow the parent widget as shown above.</p> <p>Here is the complete code from main.dart file for this example.</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;](grey, 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;](OverflowBox( color: #9cdcfe;](minHeight: color: #b5cea8;](50, color: #9cdcfe;](minWidth: color: #b5cea8;](50, color: #9cdcfe;](maxHeight: color: #b5cea8;](200, color: #9cdcfe;](maxWidth: color: #b5cea8;](200, color: #9cdcfe;](child: color: #4ec9b0;](Container( color: #9cdcfe;](color: color: #4ec9b0;](Colors.color: #9cdcfe;](green, color: #9cdcfe;](height: color: #b5cea8;](100, color: #9cdcfe;](width: color: #b5cea8;](100, ), ), ); }, ), ); } } ` Thanks,Srikanth</p>


Tags: bigger than parent widget; make child widget grow beyond parent widget; Overflow parent widget;








0 Comments
Login to comment.
Recent Comments