πŸ§™β€β™‚οΈAnimations

Animations are a crucial part of modern UI/UX design, allowing developers to create visually appealing and dynamic applications. Flutter provides a powerful and flexible framework for working with animations.

1. Basic Animation πŸŒ€

Basic animations involve animating a single property over time. Flutter's AnimationController and Tween classes are typically used for this purpose.

AnimationController controller;
Animation<double> animation;

@override
void initState() {
  super.initState();

  controller = AnimationController(
    duration: const Duration(seconds: 2),
    vsync: this,
  );

  animation = Tween<double>(
    begin: 0,
    end: 300,
  ).animate(controller)
    ..addListener(() {
      setState(() {});
    });

  controller.forward();
}

@override
void dispose() {
  controller.dispose();
  super.dispose();
}

2. Animated Widgets 🎑

Flutter provides several animated widgets for common animations, like AnimatedOpacity, AnimatedPositioned, and AnimatedContainer.

3. Custom Animations 🎨

For more complex animations, you can create your own custom animated widgets.

Complete Example Code πŸ“œ

Here's a complete Flutter app example demonstrating a basic animation using AnimationController and Tween:

In this example:

  • We first create an AnimationController and a Tween object.

  • The Tween object specifies the beginning and ending values for the animation.

  • We start the animation by calling controller.forward().

  • We use the addListener method to rebuild our widget each time the animation value changes.

  • In the build method, we create a Container whose width and height are set to the current value of the animation, creating a growing square animation.


Assignments πŸ“

Last updated

Was this helpful?