sizedBox method

SizedBox sizedBox({
  1. double? width,
  2. double? height,
})

Wraps the widget in a SizedBox with the specified dimensions.

Creates a SizedBox that constrains the widget to the specified width and/or height. If only one dimension is specified, the other dimension will be determined by the widget's intrinsic size.

Parameters:

  • width: The width constraint for the widget. If null, width is unconstrained.
  • height: The height constraint for the widget. If null, height is unconstrained.

Returns a SizedBox widget containing this widget as its child.

Example:

Container(color: Colors.blue)
  .sizedBox(width: 100, height: 50); // Fixed 100x50 blue rectangle

Text('Long text that will be constrained')
  .sizedBox(width: 200); // Fixed width, height determined by text

Implementation

SizedBox sizedBox({
  double? width,
  double? height,
}) =>
    SizedBox(
      width: width,
      height: height,
      child: this,
    );