OpenDigg

Hero Animation

Hero Animation facilitates developers in crafting diverse animation effects with ease and efficiency, thanks to its simple API and high-performance architecture.

Hero Animation, crafted by Didin Leo, is a library dedicated to animating creations with a variety of effects such as fade-in, fade-out, scaling, and rotation. Its hallmark lies in its rich functionality, ease of use, and exceptional performance, ensuring smooth animations.

The simplicity of Hero Animation's API allows developers to quickly get on board with just a few lines of code. For instance, the following code snippet illustrates how to achieve a fade-in and fade-out animation effect:

import 'package:hero_animation/hero_animation.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Hero(
          tag: 'hero',
          child: Container(
            color: Colors.red,
            width: 100,
            height: 100,
          ),
          onEnter: (child) {
            child.animate(
              duration: Duration(seconds: 1),
              curve: Curves.easeInOut,
              opacity: 0.0,
            );
          },
          onExit: (child) {
            child.animate(
              duration: Duration(seconds: 1),
              curve: Curves.easeInOut,
              opacity: 1.0,
            );
          },
        ),
      ),
    );
  }
}

In this example, the Hero component is utilized to create the animation effect. The tag and child properties of the Hero component are specified to identify the target element of the animation. The onEnter and onExit callbacks execute during the animation's entrance and exit, respectively. Here, the onEnter callback sets the target element's opacity to 0, while the onExit callback restores the opacity to 1.

Additionally, Hero Animation caters to varying needs with numerous other animation effects. For instance, the following code demonstrates a scaling animation effect:

import 'package:hero_animation/hero_animation.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Hero(
          tag: 'hero',
          child: Container(
            color: Colors.red,
            width: 100,
            height: 100,
          ),
          onEnter: (child) {
            child.animate(
              duration: Duration(seconds: 1),
              curve: Curves.easeInOut,
              scale: 2.0,
            );
          },
          onExit: (child) {
            child.animate(
              duration: Duration(seconds: 1),
              curve: Curves.easeInOut,
              scale: 1.0,
            );
          },
        ),
      ),
    );
  }
}

In this snippet, the onEnter callback sets the target element's scaling factor to 2, while the onExit callback resets it to 1.

Hero Animation is indeed a powerful library aiding developers in swiftly creating an array of rich animation effects.

About the author
Robert Harris

Robert Harris

I am a zealous AI info-collector and reporter, shining light on the latest AI advancements. Through various channels, I encapsulate and share innovation with a broader audience.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to OpenDigg.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.