Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Animations in Flutter

Animations in Flutter

A quick intorduction to animations in Flutter

Eoin Fogarty

December 16, 2018
Tweet

More Decks by Eoin Fogarty

Other Decks in Programming

Transcript

  1. - Is an animation of type Animation<double> - Default range

    0.0 to 1.0 - Default Linear curve - Duration - Defines the length of the animation - Play-Stop-Reverse-Repeat-Reset-Resume - AnimateTo-AnimateWith-Fling AnimationController controller = AnimationController( value: 0.0, duration: const Duration(milliseconds: 2000), vsync: this); controller.forward();
  2. - Animation Status - Dismissed, completed, forward reverse - Animation

    Value - AnimateTo-AnimateWith-Fling - Duration and Value - Is listenable - add/remove value listeners - add/remove status listeners - Calls listeners prior to rebuild
  3. - Non-Linear transformation of a curve. - As defined in

    Curves.x - Must map between 0.0 and 1.0 - Create custom curves final CurvedAnimation curve = CurvedAnimation(parent: controller, curve: Curves.elasticOut);
  4. CurvedAnimation wraps the object it’s modifying—you don’t subclass AnimationController to

    implement a curve. class ShakeCurve extends Curve { @override double transform(double t) { return math.sin(t * math.PI * 2); } }
  5. class AnimationPage extends StatefulWidget { _AnimationPageState createState() => _AnimationPageState(); }

    class _AnimationPageState extends State<AnimationPage> { Widget build(BuildContext context) { return Center( child: Icon( Icons.android, ), ); } }
  6. class _AnimationPageState extends State<AnimationPage> with SingleTickerProviderStateMixin { AnimationController controller; initState()

    { super.initState(); controller = AnimationController( value: 0.0, duration: const Duration(milliseconds: 2000), vsync: this); controller.forward(); } Widget build(BuildContext context) { ... } dispose() { controller.dispose(); super.dispose(); } }
  7. class _AnimationPageState extends State<AnimationPage> with SingleTickerProviderStateMixin { AnimationController controller; Animation<double>

    sizeAnimation; initState() { super.initState(); sizeAnimation = Tween(begin: 0.0, end: 320.0).animate(controller); … } Widget build(BuildContext context) { return Center( child: Icon(Icons.android, size: sizeAnimation.value), ); } dispose() {...}
  8. class _AnimationPageState extends State<AnimationPage> with SingleTickerProviderStateMixin { ... initState() {

    super.initState(); controller = AnimationController( value: 0.0, duration: const Duration(milliseconds: 2000), vsync: this); final CurvedAnimation curve = CurvedAnimation(parent: controller, curve: Curves.elasticOut); sizeAnimation = Tween(begin: 0.0, end: 320.0).animate(curve); … } Widget build(BuildContext context) { ... } dispose() {...}
  9. - No Animation object needed - Automatically interpolate and animate

    - You can change the Curve and Duration Examples: - AnimatedAlign - AnimatedContainer - AnimatedDefaultTextStyle - AnimatedOpacity - AnimatedPadding - AnimatedPhysicalModel - AnimatedPositioned - AnimatedPositionedDirectional - AnimatedTheme