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

All the animations are controlled by a AnimationController The controller is created in the initState method of the parent AnimatedWidget This method controls the flow of the animation

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);
  }
}