configAnimation method

void configAnimation({
  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

Configures and starts the animation based on the provided parameters.

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 configAnimation({
  required Duration delay,
  required bool animate,
  required bool manualTrigger,
  required bool infinite,
  Function? onFinish,
  Function(AnimationController controller)? controllerCallback,
}) {
  /// If the user wants to check if the animation finished, we add a listener
  if (onFinish != null) {
    controller.addStatusListener((AnimationStatus status) {
      if (status == AnimationStatus.completed) {
        onFinish(AnimateDoDirection.forward);
      } else if (status == AnimationStatus.dismissed) {
        onFinish(AnimateDoDirection.backward);
      }
    });
  }

  /// If the user wants to trigger the animation manually, we expose the controller
  if (!manualTrigger && animate) {
    Future.delayed(delay, () {
      if (disposed) return;
      (infinite) ? controller.repeat() : controller.forward();
    });
  }

  /// Returns the controller if the user requires it
  if (controllerCallback != null) {
    controllerCallback(controller);
  }
}