animate_do Package

repository·master·Indexed 18 days ago

https://github.com/klerith/animate_do_package

A Flutter animation package inspired by Animate.css that provides a wide variety of pre-built animations including fade, bounce, slide, and attention seekers. It supports two syntaxes: Class syntax for wrapping widgets and Sugar syntax for extension method chaining. The package features zero external dependencies, supports Dart 3 and Null Safety, and offers advanced control through properties like manualTrigger, onFinish callbacks, and AnimationController access.

Tokens
8.4K
Snippets
26
Records
34
Agent score
61%

What's inside animate_do

  1. Manually control animations with `manualTrigger`

    master

    For full control over playback (e.g., precise timing or custom triggers), set manualTrigger: true. You must then use the controller callback to capture the AnimationController and call .forward() or .reverse() explicitly.

    class _MyWidgetState extends State<MyWidget> {
      late AnimationController animateController;
    
      @override
      Widget build(BuildContext context) {
        return FadeInUp(
          manualTrigger: true,
          controller: (controller) => animateController = controller,
          child: YourWidget(),
        );
      }
    }
  2. Get started with animate_do

    master

    animate_do is a Flutter animation package inspired by Animate.css. It allows you to add animations to any widget by wrapping it in an animation widget or using extension methods. It features zero external dependencies and supports Dart 3 and Null Safety.

    /* Drop an animation widget around any widget to begin. */
    FadeIn(child: const Square());
  3. Trigger animations using the `animate` property

    master

    To control when an animation plays, use the animate boolean property. Setting animate: true plays the animation forward, while animate: false reverses it. This is designed to work seamlessly with state management solutions like setState, Bloc, Provider, or Redux.

    FadeIn(animate: animate, child: const Square())
  4. Use the two animation syntaxes: Sugar and Class

    master

    The package provides two ways to apply animations:

    1. Sugar Syntax: Uses extension methods on widgets to chain animations fluently.
    2. Class Syntax: Uses specific animation widgets (e.g., FadeInLeft) that wrap a child widget.

    Both syntaxes are fully supported and achieve the same result.

    // Sugar Syntax
    const Square().fadeInLeft()
    
    // Class Syntax
    FadeInLeft(child: const Square())
  5. Chain multiple animations sequentially

    master

    You can chain multiple animations together using the Sugar syntax. This is particularly useful for complex sequences or combining standard animations with custom movement animations like MoveTo or MoveToArc.

    // Chaining standard animations
    Square()
      .tada()
      .wobble()
      .fadeIn()
    
    // Chaining with custom movement animations
    const Square()
      .moveTo(top: 30)
      .moveTo(
        left: 30,
        delay: const Duration(seconds: 1),
      )
      .moveToArc(
        bottom: 30,
        right: 30,
        delay: const Duration(seconds: 2),
      )
      .fadeOut(
        delay: const Duration(seconds: 2),
      )
  6. Handle animation completion with `onFinish`

    master

    The onFinish callback is executed when an animation finishes. It provides an AnimateDoDirection argument, which tells you if the animation was moving forward or backward.

    // Sugar syntax
    const Square().fadeIn(
      animate: animate,
      delay: const Duration(milliseconds: 100),
      onFinish: (direction) => print('$direction'),
    )
    
    // Class syntax
    FadeIn(
      animate: animate,
      delay: const Duration(milliseconds: 100),
      onFinish: (direction) => print('$direction'),
      child: const Square(),
    )
  7. Available animation types

    master

    The package includes several categories of animations:

    • Fade: FadeIn, FadeInDown, FadeInDownBig, FadeInUp, FadeInUpBig, FadeInLeft, FadeInLeftBig, FadeInRight, FadeInRightBig, and their FadeOut counterparts.
    • Bounce In: BounceInDown, BounceInUp, BounceInLeft, BounceInRight.
    • Elastic In: ElasticIn, ElasticInDown, ElasticInUp, ElasticInLeft, ElasticInRight.
    • Slide In: SlideInDown, SlideInUp, SlideInLeft, SlideInRight.
    • Back In / Out: BackInDown, BackInUp, BackInLeft, BackInRight, BackOutDown, BackOutUp, BackOutLeft, BackOutRight.
    • Flip In: FlipInX, FlipInY.
    • Zoom: ZoomIn, ZoomOut.
    • Attention Seekers (Support infinite property): Bounce, Dance, Flash, Pulse, Flip, Roulette, ShakeX, ShakeY, Spin, SpinPerfect, Swing, HeartBeat, Wobble, Jello, Tada, RubberBand.
    • Custom Movement: MoveTo, MoveToArc.
  8. Configure animation properties

    master

    All animation widgets share a common set of properties for customization:

    PropertyTypeDescription
    keyKeyOptional widget key reference
    childWidgetRequired widget to animate
    durationDurationDuration of the animation
    delayDurationDelay before the animation starts
    fromdoubleInitial or final value for more pronounced slide/fade effects
    animateboolToggle falsetrue to trigger; works with state management
    infiniteboolLoops the animation indefinitely
    spinsdoubleNumber of rotations (applies to Spin, Roulette, SpinPerfect)
    manualTriggerboolDisables auto-play; requires the controller callback to drive animation
    controllerFunctionExposes the AnimationController for advanced control
    onFinishFunctionCallback fired when animation completes; receives an AnimateDoDirection
    curveCurveCustom easing curve
  9. Use the Wobble animation

    master

    The Wobble animation wobbles the child horizontally while rotating it slightly, mimicking the wobble animation from Animate.css. The horizontal movement is calculated as a fraction of the available screen width.

    You can use it either by wrapping a widget with the Wobble class or by using the wobble() extension method on any Widget.

    // Using the extension method (recommended)
    MyWidget().wobble(
      duration: Duration(milliseconds: 1500),
      infinite: true,
    );
    
    // Using the Wobble widget directly
    Wobble(
      child: MyWidget(),
      duration: Duration(milliseconds: 1500),
    );
  10. Use the BackOutDown animation

    master

    The BackOutDown animation shrinks the child and slides it downward while fading it out. You can use it either by wrapping a widget with the BackOutDown class or by using the backOutDown() extension method on any Widget.

    Properties

    • child: The widget to be animated.
    • duration: The total time the animation takes (defaults to 1200ms).
    • delay: The time to wait before starting the animation.
    • curve: The animation curve (defaults to Curves.easeOut).
    • animate: Whether the animation should start automatically (defaults to true).
    • manualTrigger: If true, the animation will not start automatically and requires manual control via a controller.
    • controller: An AnimateDoController to programmatically control the animation.
    • onFinish: A callback function executed when the animation completes.
    • to: The final vertical offset in logical pixels (defaults to 1000.0).
    // Using the extension method (recommended)
    import 'package:animate_do/animate_do.dart';
    
    Text('Hello World').backOutDown(
      duration: Duration(milliseconds: 800),
      to: 500.0,
    );
    
    // Using the widget directly
    BackOutDown(
      child: Text('Hello World'),
      to: 500.0,
    );
  11. Use the BackInRight animation

    master

    The BackInRight animation combines a small fade-in with a slide from the right, mimicking the backInRight animation from Animate.css. You can use it either by wrapping a widget with the BackInRight class or by using the backInRight() extension method on any Widget.

    Properties

    PropertyTypeDefaultDescription
    childWidgetRequiredThe widget to be animated.
    durationDurationDuration(milliseconds: 1200)The total length of the animation.
    delayDurationDuration.zeroThe delay before the animation starts.
    curveCurveCurves.easeOutThe animation curve.
    animatebooltrueWhether the animation should start automatically.
    manualTriggerboolfalseIf true, the animation requires manual control via a controller.
    fromdouble1000.0The horizontal offset (in logical pixels) from which the child starts its slide.
    // Using the extension method (Recommended)
    Widget myWidget = Container(color: Colors.blue).backInRight(
      duration: Duration(milliseconds: 800),
      from: 500.0,
    );
    
    // Using the widget directly
    Widget myWidget = BackInRight(
      duration: Duration(milliseconds: 800),
      from: 500.0,
      child: Container(color: Colors.blue),
    );
  12. Use the BackInUp animation widget

    master

    The BackInUp animation combines a small fade-in with a downward slide, mimicking the backInUp animation from Animate.css. You can use it either by wrapping a widget with the BackInUp class or by using the backInUp() extension method on any Widget.

    Properties

    PropertyTypeDescription
    childWidgetThe widget to be animated.
    durationDurationThe length of the animation. Defaults to 1200ms.
    delayDurationThe delay before the animation starts. Defaults to Duration.zero.
    curveCurveThe animation curve. Defaults to Curves.easeOut.
    animateboolWhether the animation should start automatically. Defaults to true.
    manualTriggerboolIf true, the animation requires manual control via a controller. Defaults to false.
    controllerAnimateDoControllerCallback?A callback to control the animation.
    onFinishAnimateDoFinishCallback?A callback triggered when the animation completes.
    fromdoubleThe vertical offset (in logical pixels) where the child starts from. Defaults to 1000.0.
    // Using the extension method (recommended)
    Widget myWidget = Text('Hello World').backInUp(
      duration: Duration(milliseconds: 800),
      from: 500.0,
    );
    
    // Using the widget directly
    Widget myWidget = BackInUp(
      duration: Duration(milliseconds: 800),
      from: 500.0,
      child: Text('Hello World'),
    );