A widget that imposes additional constraints on its child.

For example, if you wanted child to have a minimum height of 50.0 logical pixels, you could use const BoxConstraints(minHeight: 50.0) as the constraints.

Sample code

This snippet makes the child widget (a Card with some Text) fill the parent, by applying BoxConstraints.expand constraints:

new ConstrainedBox(
  constraints: const BoxConstraints.expand(),
  child: const Card(child: const Text('Hello World!')),

The same behaviour can be obtained using the new SizedBox.expand widget.

See also:

  • BoxConstraints, the class that describes constraints.
  • SizedBox, which lets you specify tight constraints by explicitly specifying the height or width.
  • FractionallySizedBox, a widget that sizes its child to a fraction of the total available space.
  • AspectRatio, a widget that attempts to fit within the parent's constraints while also sizing its child to match a given sapect ratio.


ConstrainedBox({Key key, @required BoxConstraints constraints, Widget child })
Creates a widget that imposes additional constraints on its child. [...]


constraints BoxConstraints
The additional constraints to impose on the child.
child Widget
The widget below this widget in the tree.
final, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


createRenderObject(BuildContext context) RenderConstrainedBox
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget. [...]
debugFillDescription(List<String> description) → void
Add additional information to the given description for use by toString. [...]
updateRenderObject(BuildContext context, RenderConstrainedBox renderObject) → void
Copies the configuration described by this RenderObjectWidget to the given RenderObject, which will be of the same type as returned by this object's createRenderObject. [...]
createElement() SingleChildRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
didUnmountRenderObject(RenderObject renderObject) → void
A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object's createRenderObject.
@protected, inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
Returns a string representation of this object.
toStringShort() String
A short, textual description of this widget.


operator ==(other) bool
The equality operator. [...]