TimelineAnimation<T> constructor
TimelineAnimation<T> ({
- PropertyLerp<
T> ? lerp, - required List<
Keyframe< keyframes,T> >
Creates a timeline animation from a list of keyframes.
Parameters
lerp- Optional interpolation function. Uses defaultLerp if not provided.keyframes- The list of keyframes defining the animation. Must not be empty.
Returns
A new TimelineAnimation with calculated total duration.
Example
final timeline = TimelineAnimation<Color>(
lerp: Transformers.typeColor,
keyframes: [
AbsoluteKeyframe(Duration(milliseconds: 300), Colors.red, Colors.blue),
RelativeKeyframe(Duration(milliseconds: 200), Colors.green),
],
);
Implementation
factory TimelineAnimation({
PropertyLerp<T>? lerp,
required List<Keyframe<T>> keyframes,
}) {
lerp ??= defaultLerp;
assert(keyframes.isNotEmpty, 'No keyframes found');
Duration current = Duration.zero;
for (var i = 0; i < keyframes.length; i++) {
final keyframe = keyframes[i];
assert(keyframe.duration.inMilliseconds > 0, 'Invalid duration');
current += keyframe.duration;
}
return TimelineAnimation._(
lerp: lerp,
totalDuration: current,
keyframes: keyframes,
);
}