Skip to content
pubscout

dimension

0.2.1, released 5 weeks ago by wenkaifan.com

Mimics CSS length units (px, percentage, vw, vh, vmin, vmax) for responsive Flutter layouts.

WASM-ready
$ flutter pub add dimension
Source repository

What it does

Introduces a Dimension class that mimics CSS length units, allowing developers to calculate sizes based on parent constraints and screen dimensions. It includes DimensionSizedBox and AnimatedDimensionSizedBox widgets to simplify responsive design and animations.

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

Use it when

  • You want to use CSS-like length units such as vw, vh, percentage, or vmin/vmax in Flutter.
  • You need to easily tween or animate sizes across different units.
  • You want a SizedBox alternative that reacts to screen size and parent constraints using Dimension values.

Skip it when

  • You are already using a comprehensive responsive layout framework that provides its own scaling mechanism.
  • You do not need CSS-style units and standard Flutter constraints are sufficient.

Strengths

  • Supports multiple CSS-like units including px, percentage, vw, vh, vmin, and vmax.
  • Supports serialization and deserialization of dimensions.
  • Provides built-in widgets like DimensionSizedBox and AnimatedDimensionSizedBox.

Weaknesses

  • Requires explicitly passing screen sizes or using its specific wrapper widgets.
  • Relies on manual context/constraint handling outside of the provided widgets.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
1
var length = 10.toPXLength;
double px = length.toPX(constraint: 100, screenSize: MediaQuery.sizeOf(context));

Alternatives

Packages that do the same job and could replace dimension.

  • responsive_framework

    If you need full-scale adaptive and responsive scaling across different screen sizes automatically.

  • sizer

    If you prefer calculating sizes based on device screen width and height percentages via simple extensions.

Works with

Packages commonly used together with dimension: ones it builds on, ones built on it, and its own family.