buildAnimation method

void buildAnimation({
  1. required Duration delay,
  2. required bool animate,
  3. required bool manualTrigger,
  4. required bool infinite,
  5. Function? onFinish,
  6. dynamic controllerCallback(
    1. AnimationController controller
    )?,
})
inherited

Builds and controls the animation based on the provided parameters.

This method handles:

  • Delayed animation start
  • Infinite animation loops
  • Animation reversal
  • Manual animation control

Parameters:

  • delay: Duration to wait before starting the animation
  • animate: Whether the animation should start automatically
  • manualTrigger: Whether animation requires manual triggering
  • infinite: Whether animation should loop infinitely
  • onFinish: Callback function when animation completes
  • controllerCallback: Callback to access the animation controller

Implementation

void buildAnimation({
  required Duration delay,
  required bool animate,
  required bool manualTrigger,
  required bool infinite,
  Function? onFinish,
  Function(AnimationController controller)? controllerCallback,
}) {
  /// Launch the animation ASAP or wait until needed
  print("animate: $animate");

  if (animate && !manualTrigger) {
    // controller.value = 0;

    Future.delayed(delay, () {
      if (disposed) return;
      if (infinite) {
        controller.repeat();
        return;
      }

      (animate) ? controller.forward() : controller.reverse();
    });
  }

  /// If the animation already happen, we can animate it back
  if (!animate) {
    if (disposed) return;
    if (infinite) {
      controller.stop();
      return;
    }

    // If the animation is finished, we need to reset the animation to the original state
    // after the animation is finished just for the following classes:
    if (resetAnimationClasses.contains(this.runtimeType) && !isFirstTime) {
      controller.value = 0;
      return;
    }

    controller.animateBack(0);
    isFirstTime = false;
  }
}