SizedBox Widget

A box with a specified size.

If given a child, this widget forces its child to have a specific width and/or height (assuming values are permitted by this widget's parent). If either the width or height is null, this widget will try to size itself to match the child's size in that dimension. If the child's size depends on the size of its parent, the height and width must be provided.

If not given a child, SizedBox will try to size itself as close to the specified height and width as possible given the parent's constraints. If height or width is null or unspecified, it will be treated as zero.

SizedBox(
	width: 200.0,
	height: 300.0,
	child: const Card(child: Text('Hello World!')),
)

Arguments

width

If non-null, requires the child to have exactly this width.

height

If non-null, requires the child to have exactly this height.

The difference between Container and SizedBox is that the SizedBox is not only simpler, but it also can be made const, while Container cannot. If you need a box with color you cannot use SizedBox. Instead you need to use Container with width and height arguments for this purpose.

The new SizedBox.expand constructor can be used to make a SizedBox that sizes itself to fit the parent. It is equivalent to setting width and height to double.infinity.

Container(
	color : Colors.blue,
	width: 200,
	height: 300,
	child: SizedBox.expand(
		child: const Card(child: Text('Hello World!')),
	),
),