Skip to content
pubscout

widget_size

1.0.0, released 4 years ago by buildtoapp.com

A single-purpose widget to calculate its size after being built and attached to the tree.

WASM-ready
$ flutter pub add widget_size
Source repository

What it does

Provides a WidgetSize wrapper that invokes an onChange callback with the computed Size once the child is built and attached to the widget tree. This allows developers to read the dynamic layout dimensions of a widget.

AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to obtain the runtime dimensions (width and height) of a widget after it has been rendered.
  • You want to dynamically adjust state or layout based on an existing child widget's measured size.

Skip it when

  • You can accomplish the same layout constraints using standard Flutter layout widgets like LayoutBuilder or SizedBox.
  • You require complex custom painting or rendering layers.

Strengths

  • Simple and straightforward API for size calculation.
  • Cross-platform compatibility supporting Android, iOS, web, Windows, macOS, and Linux.

Weaknesses

  • Triggers a callback post-build, which can lead to rebuild loops if state updates modify constraints incorrectly.
  • Very minimal documentation and features beyond basic size observation.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
0

No native setup or build_runner required.

WidgetSize(
  onChange: (Size size) {
    _yourHeight = size.height;
    _yourWidth = size.width;
  },
  child: Container(
    height: _yourHeight,
    width: _yourWidth,
    color: Theme.of(context).primaryColor,
  ),
)

Alternatives

Packages that do the same job and could replace widget_size.