translation method Null safety

Stream<num> translation(
  1. num startValue,
  2. num targetValue,
  3. num time,
  4. [TransitionFunction transition = Transition.linear]
)

Returns a Stream of translated values which fires for time seconds.

The stream returns the translated values based on the transition and the time elapsed since the start of the method. The stream ends automatically after time seconds.

This method is based on the onElapsedTimeChange stream and is therefore executed before all other animatables.

var transition = Transition.easeInSine;
await for (var value in juggler.translation(0.0, 10.0, 5.0, transition)) {
  print(value);
}

Implementation

Stream<num> translation(num startValue, num targetValue, num time,
    [TransitionFunction transition = Transition.linear]) async* {
  final startTime = elapsedTime;
  final deltaValue = targetValue - startValue;
  await for (var elapsedTime in onElapsedTimeChange) {
    final currentTime = elapsedTime - startTime;
    final clampedTime = currentTime < time ? currentTime : time;
    yield startValue + deltaValue * transition(clampedTime / time);
    if (currentTime >= time) break;
  }
}