AnimationTimeline.pulse constructor

AnimationTimeline.pulse({
  1. required AnimationController controller,
  2. Duration hold = Duration.zero,
  3. Duration rest = Duration.zero,
  4. bool repeat = false,
  5. Object? id,
  6. String? forwardLabel,
  7. String? holdLabel,
  8. String? reverseLabel,
  9. String? restLabel,
  10. void onStepStart(
    1. int index,
    2. AnimationTimelineStep step,
    3. TimelineDirection direction
    )?,
  11. void onStepComplete(
    1. int index,
    2. AnimationTimelineStep step,
    3. TimelineDirection direction
    )?,
})

Builds a common pulse cycle for one controller.

The generated sequence is:

  1. animate forward
  2. optional hold
  3. animate reverse
  4. optional rest

This is useful for breathing indicators, spotlight pulses, and repeated emphasis without hand-writing the same four-step sequence each time.

Implementation

factory AnimationTimeline.pulse({
  required AnimationController controller,
  Duration hold = Duration.zero,
  Duration rest = Duration.zero,
  bool repeat = false,
  Object? id,
  String? forwardLabel,
  String? holdLabel,
  String? reverseLabel,
  String? restLabel,
  void Function(
    int index,
    AnimationTimelineStep step,
    TimelineDirection direction,
  )?
  onStepStart,
  void Function(
    int index,
    AnimationTimelineStep step,
    TimelineDirection direction,
  )?
  onStepComplete,
}) {
  final steps = <AnimationTimelineStep>[
    AnimationTimelineStep.forward(
      controller,
      label: forwardLabel ?? 'pulse-in',
    ),
    if (hold > Duration.zero)
      AnimationTimelineStep.delay(hold, label: holdLabel ?? 'hold'),
    AnimationTimelineStep.reverse(
      controller,
      label: reverseLabel ?? 'pulse-out',
    ),
    if (rest > Duration.zero)
      AnimationTimelineStep.delay(rest, label: restLabel ?? 'rest'),
  ];

  return AnimationTimeline(
    steps: steps,
    repeat: repeat,
    id: id,
    onStepStart: onStepStart,
    onStepComplete: onStepComplete,
  );
}