fitted_scale 1.0.1 copy "fitted_scale: ^1.0.1" to clipboard
fitted_scale: ^1.0.1 copied to clipboard

A widget that scales its child prior to layout, the final rendering box consumes only as much space as required by the scaled child.

Fitted scale is a widget that scales its child prior to layout. Unlike Transform.scale(), which applies a transform just prior to painting, this widget applies its scaling prior to layout, which means the entire rendered box consumes only as much space as required by the scaled child. You may think of this as the scaling version of RotatedBox.

simple demo

Usage #

Scale your widget in a similar way as Transform.scale()

Applies a uniform scaling:

FittedScale(
  scale: 0.6,
  child: FlutterLogo( size: 110 )
),

Specifics horizontal and vertical scaling independently:

FittedScale(
  scaleX: 0.6,
  scaleY: 1.3
  child: FlutterLogo( size: 110 )
),

More examples #

This is an example of scaling up an material IconButton. The finally layout is more desirable compared to adopting Transform.scale().

Row(children: [
  FittedScale(
    scale: 2.0,
    child: IconButton( onPressed: () {}, icon: Icon(Icons.read_more))),
  Container(
    color: Colors.green,
    child: FlutterLogo( size: 110 ),
  ),
])

simple demo

Performing scaling prior to layout can sometimes avoid unwanted clipping.

Row(children: [
  Container(
    color: Colors.amber,
    child: FittedScale(
        scaleX: 2.4,
        child: FlutterLogo( size: 110 )),
  ),
  Container(
    color: Colors.green,
    child: FittedScale(
      scaleY: 0.75,
      child: FlutterLogo( size: 110 )),
  ),
]),

simple demo

Notice that if the above is implemented with Transform.scale(), two sides of the Flutter logo(yellow background) will be trimmed.

Last but not least... #

Please feel free to report any issues or suggest improvements here.

2
likes
0
points
127
downloads

Publisher

unverified uploader

Weekly Downloads

A widget that scales its child prior to layout, the final rendering box consumes only as much space as required by the scaled child.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on fitted_scale