BoxConstraints

BoxConstraints is used to proved the constraints value to the ConstrainedBox widget.

You can change a Widget's sizing behaviour beased on the BoxConstraints given to it. You can provide BoxConstraints in ConstrainedBox widget. First lets explore few BoxConstraints that we can use.

BoxConstraints()

Creates box constraints with the given constraints.

BoxConstraints({
	double minWidth: 0.0, 
	double maxWidth: double.infinity, 
	double minHeight: 0.0, 
	double maxHeight: double.infinity
})

BoxConstraints.expand({double width, double height})

Creates box constraints that expand to fill another box constraints.

If width or height is given, the constraints will require exactly the given value in the given dimension.

If width and height is not given, then the default value is double.Infinity, means the widget will tries to fill the parent widget.

BoxConstraints.loose(Size size)

Creates box constraints that forbid sizes larger than the given size.

BoxConstraints.tight(Size size)

Creates box constraints that is respected only by the given size.

To explore more see BoxConstraints class.

ConstrainedBox

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.

Properties

constraints

Used to provide additional constraints to child.

child

The child widget.

Example

The following example will make the Card widget to fill its parent widget.

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