runTransition method
void
runTransition(
- String propertyName,
- dynamic begin,
- dynamic end
)
Implementation
void runTransition(String propertyName, begin, end) {
if (_hasRunningTransition(propertyName)) {
Animation animation = _propertyRunningTransition[propertyName]!;
if (CSSTransitionHandlers.containsKey(propertyName) && animation.effect is KeyframeEffect) {
KeyframeEffect effect = animation.effect as KeyframeEffect;
var interpolation = effect.interpolations.firstWhere((interpolation) => interpolation.property == propertyName);
var stringifyFunc = CSSTransitionHandlers[propertyName]![2];
// Matrix4 begin, Matrix4 end, double t, String property, CSSRenderStyle renderStyle
begin = stringifyFunc(interpolation.lerp(interpolation.begin, interpolation.end, animation.progress, propertyName, this));
}
CSSTransitionHandlers[propertyName];
animation.cancel();
// An Event fired when a CSS transition has been cancelled.
target.dispatchEvent(Event(EVENT_TRANSITION_CANCEL));
}
if (begin == null || (begin is String && begin.isEmpty)) {
begin = CSSInitialValues[propertyName];
if (begin == CURRENT_COLOR) {
begin = currentColor;
}
}
if (end is String && end.isEmpty) {
end = CSSInitialValues[propertyName];
}
EffectTiming? options = getTransitionEffectTiming(propertyName);
List<Keyframe> keyframes = [
Keyframe(propertyName, begin, 0, LINEAR),
Keyframe(propertyName, end, 1, LINEAR),
];
KeyframeEffect effect = KeyframeEffect(this, target, keyframes, options);
Animation animation = Animation(effect, target.ownerDocument.animationTimeline);
_propertyRunningTransition[propertyName] = animation;
animation.onstart = () {
// An Event fired when a CSS transition is created,
// when it is added to a set of running transitions,
// though not necessarily started.
target.dispatchEvent(Event(EVENT_TRANSITION_START));
};
animation.onfinish = (AnimationPlaybackEvent event) {
_propertyRunningTransition.remove(propertyName);
target.setRenderStyle(propertyName, end);
// An Event fired when a CSS transition has finished playing.
target.dispatchEvent(Event(EVENT_TRANSITION_END));
};
target.dispatchEvent(Event(EVENT_TRANSITION_RUN));
animation.play();
}