Sized Box
The Sized Box is a simple, invisible widget that creates a box with a specific width and height. Its primary purpose is to add fixed-size gaps or spacing within layouts.
Core Concept: Creating Space
Think of the Sized Box as a rigid, empty spacer. While other widgets like Container can have padding and margins, the Sized Box has only one job: to occupy a precise amount of space. This makes it the most efficient and straightforward way to add gaps between widgets in a Column or Row.
In a
Column, a Sized Box with aHeightcreates vertical space.In a
Row, a Sized Box with aWidthcreates horizontal space.

Properties
Width
The width of the box. Can be a fixed value in pixels (px).
Height
The height of the box. Can be a fixed value in pixels (px).
Default Properties
The Sized Box is a highly specialized layout widget. Its core properties (Width and Height) define its entire function, so it does not use the standard Default Properties for styling (like Background Color or Border).
Best Practices
Use for Spacing: The most common use case is to create space between widgets. For example, add a
Sized BoxwithHeight: 16between twoTextwidgets in aColumnto separate them.Constraining a Child: While primarily used for spacing, if you place another widget inside a Sized Box, it will force the child to adopt the Sized Box's dimensions. This can be useful for giving a specific size to a widget that doesn't have its own width or height properties.
Efficiency: For creating simple, empty space, the Sized Box is more performant than using a
Containerwith padding or margins.
Last updated