SizedBox

Creates a box with fixed dimensions. Can contain a child widget or be used as empty space.

Basic Usage

SizedBox(Width(100), Height(50))

Options

Option Type Description Example
Width float32 Sets the fixed width in dp Width(100)
Height float32 Sets the fixed height in dp Height(50)

Examples

// Fixed size empty box (for spacing)
SizedBox(Width(100), Height(50))

// Fixed width only
SizedBox(Width(200))

// Fixed height only (useful for vertical spacing)
SizedBox(Height(20))

// SizedBox with child widget
SizedBox(Width(200), Height(100), Text("Constrained"))

// Using SizedBox for spacing in a Column
Column([]any{
    Text("Above"),
    SizedBox(Height(32)),
    Text("Below"),
})

// Using SizedBox for spacing in a Row
Row([]any{
    Button("Left"),
    SizedBox(Width(16)),
    Button("Right"),
})

// Constrain a widget to specific dimensions
SizedBox(
    Width(150),
    Height(40),
    Button("Fixed Size Button"),
)

Note

When both width and height are specified, the child widget will be constrained to those exact dimensions. When only one dimension is specified, the other dimension will use the available space or the child’s natural size.