Animated Text Kit

repository·master·Indexed 23 days ago

https://github.com/aagarwal1012/animated-text-kit

A Flutter package providing a collection of high-quality text animations including typewriter, scale, fade, colorize, rotate, and typer effects. It features the AnimatedTextKit orchestrator for managing animation sequences, durations, and repetitions, as well as standalone widgets like TextLiquidFill.

Tokens
9.4K
Snippets
24
Records
50
Agent score
82%

What's inside animated_text_kit

  1. How animations and AnimatedTextKit work together

    master

    Since Version 3, the library uses a decoupled architecture. AnimatedTextKit acts as the controller and orchestrator, while individual animation styles (like FadeAnimatedText, ScaleAnimatedText, etc.) extend from a base AnimatedText class.

    This allows you to easily combine different animation styles within a single AnimatedTextKit widget by passing them into the animatedTexts list.

    Note on Legacy Classes: You may see classes ending in ...AnimatedTextKit (e.g., FadeAnimatedTextKit). These are legacy wrappers for backward compatibility and are deprecated. You should use the new pattern: AnimatedTextKit containing FadeAnimatedText.

    AnimatedTextKit(
      animatedTexts: [
        FadeAnimatedText(
          'Fade First',
          textStyle: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold),
        ),
        ScaleAnimatedText(
          'Then Scale',
          textStyle: TextStyle(fontSize: 70.0, fontFamily: 'Canterbury'),
        ),
      ],
    )
  2. How to create custom animations

    master

    To create a custom animation, extend the AnimatedText class and implement the following four members:

    1. Constructor: Initializes animation parameters.
    2. initAnimation: Initializes Animation instances and binds them to the provided AnimationController.
    3. animatedBuilder: A builder method that returns a Widget based on the current Animation values.
    4. completeText: Returns the Widget to display once the animation finishes (defaults to a styled Text widget).

    Once implemented, pass your custom class into the animatedTexts list of an AnimatedTextKit widget.

    AnimatedTextKit(
      animatedTexts: [
        CustomAnimatedText(
          'Insert Text Here',
          textStyle: const TextStyle(
            fontSize: 32.0,
            fontWeight: FontWeight.bold,
          ),
        ),
      ],
    ),
  3. Configure animation duration and repetition

    master

    You can customize the behavior of any AnimatedTextKit class by overriding the duration of the animation or controlling whether it loops. Set isRepeatingAnimation to false to prevent the animation from repeating.

    FadeAnimatedTextKit(
      duration: Duration(milliseconds: 5000),
      isRepeatingAnimation: false,
      text: ["do IT!", "do it RIGHT!!", "do it RIGHT NOW!!!"],
      textStyle: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold),
    );
  4. Install Animated Text Kit

    master

    To use animated_text_kit in your Flutter project, follow these steps:

    1. Add the dependency to your pubspec.yaml:
    dependencies:
      animated_text_kit: ^4.2.2
    1. Run the installation command in your terminal:
    flutter pub get
    1. Import the package in your Dart code:
    import 'package:animated_text_kit/animated_text_kit.dart';
    dependencies:
      animated_text_kit: ^4.2.2
  5. Customize iOS Launch Screen Assets

    master

    To change the launch screen image for the iOS version of your Flutter application, you can use one of two methods:

    Method 1: Direct File Replacement

    Replace the existing image files directly within the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory with your own assets.

    Method 2: Using Xcode

    1. Open your Flutter project's iOS workspace in Xcode by running: open ios/Runner.xcworkspace.
    2. In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog to replace the current launch images.
    open ios/Runner.xcworkspace
  6. Understand the AnimatedText base class

    master

    The AnimatedText class is an abstract base class used to define individual text animation styles. When implementing a custom animation, you must provide:

    • text: The string to be animated.
    • duration: The total duration for this specific text animation.
    • textAlign: The alignment of the text (defaults to TextAlign.start).
    • textStyle: The TextStyle for the text.

    Custom implementations must override:

    • initAnimation(AnimationController controller): To initialize the animation logic.
    • animatedBuilder(BuildContext context, Widget? child): To define how the text is rendered during the animation using the provided AnimationController.
  7. Migrate from FadeAnimatedTextKit to FadeAnimatedText

    master

    The FadeAnimatedTextKit class is deprecated. Instead of using the specialized kit, you should use the standard AnimatedTextKit and provide a list of FadeAnimatedText objects to its animatedTexts property.

    Old Way (Deprecated):

    FadeAnimatedTextKit(
      text: ['Text 1', 'Text 2'],
      // ... other properties
    )

    New Way (Recommended):

    AnimatedTextKit(
      animatedTexts: [
        FadeAnimatedText('Text 1'),
        FadeAnimatedText('Text 2'),
      ],
      // ... other properties
    )
  8. Use TypewriterAnimatedTextKit

    master

    The TypewriterAnimatedTextKit provides a typewriter-style animation effect.

    TypewriterAnimatedTextKit(
      onTap: () {
        print("Tap Event");
      },
      text: [
        "Discipline is the best tool",
        "Design first, then code",
        "Do not patch bugs out, rewrite them",
        "Do not test bugs out, design them out",
      ],
      textStyle: TextStyle(
        fontSize: 30.0,
        fontFamily: "Agne"
      ),
      textAlign: TextAlign.start,
      alignment: AlignmentDirectional.topStart // or Alignment.topLeft
    ),