cancelTransitionFor method

void cancelTransitionFor(
  1. String propertyName
)

Implementation

void cancelTransitionFor(String propertyName) {
  final Animation? animation = _propertyRunningTransition.remove(propertyName);
  if (animation != null) {
    if (DebugFlags.shouldLogTransitionForProp(propertyName)) {
      cssLogger.info('[transition][cancel] property=$propertyName');
    }
    // Compute elapsedTime at cancel as progress * duration (in seconds),
    // excluding any transition-delay.
    double elapsedSec = 0.0;
    final EffectTiming? options = getTransitionEffectTiming(propertyName);
    final double durationMs = options?.duration ?? 0.0;
    if (durationMs > 0) {
      try {
        elapsedSec = (animation.progress * durationMs) / 1000.0;
      } catch (_) {
        elapsedSec = 0.0;
      }
    }
    animation.cancel();
    // Align with runTransition() which explicitly fires transitioncancel on cancel.
    target.dispatchEvent(TransitionEvent(
      EVENT_TRANSITION_CANCEL,
      propertyName: _toHyphenatedCSSProperty(propertyName),
      elapsedTime: elapsedSec,
    ));
  }
}