AnimatedScale class Null safety

Animated version of Transform.scale which automatically transitions the child's scale over a given duration whenever the given scale changes.

This code defines a widget that uses AnimatedScale to change the size of FlutterLogo gradually to a new scale whenever the button is pressed.
class LogoScale extends StatefulWidget {
  const LogoScale({super.key});

  @override
  State<LogoScale> createState() => LogoScaleState();
}

class LogoScaleState extends State<LogoScale> {
  double scale = 1.0;

  void _changeScale() {
    setState(() => scale = scale == 1.0 ? 3.0 : 1.0);
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        ElevatedButton(
          onPressed: _changeScale,
          child: const Text('Scale Logo'),
        ),
        Padding(
          padding: const EdgeInsets.all(50),
          child: AnimatedScale(
            scale: scale,
            duration: const Duration(seconds: 2),
            child: const FlutterLogo(),
          ),
        ),
      ],
    );
  }
}

See also:

  • AnimatedRotation, for animating the rotation of a child.
  • AnimatedSize, for animating the resize of a child based on changes in layout.
  • AnimatedSlide, for animating the translation of a child by a given offset relative to its size.
  • ScaleTransition, an explicitly animated version of this widget, where an Animation is provided by the caller instead of being built in.
Inheritance

Constructors

AnimatedScale({Key? key, Widget? child, required double scale, Alignment alignment = Alignment.center, FilterQuality? filterQuality, Curve curve = Curves.linear, required Duration duration, VoidCallback? onEnd})
Creates a widget that animates its scale implicitly.
const

Properties

alignment Alignment
The alignment of the origin of the coordinate system in which the scale takes place, relative to the size of the box.
final
child Widget?
The widget below this widget in the tree.
final
curve Curve
The curve to apply when animating the parameters of this container.
finalinherited
duration Duration
The duration over which to animate the parameters of this container.
finalinherited
filterQuality FilterQuality?
The filter quality with which to apply the transform as a bitmap operation.
final
hashCode int
The hash code for this object.
nonVirtual">@nonVirtualread-onlyinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onEnd VoidCallback?
Called every time an animation completes.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
scale double
The target scale.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() ImplicitlyAnimatedWidgetState<AnimatedScale>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
protected">@protectedinherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
nonVirtual">@nonVirtualinherited