roundProgress method

double roundProgress(
  1. double progress, {
  2. required FrameRate frameRate,
})

Returns a "rounded" progress value according to the frameRate

Implementation

double roundProgress(double progress, {required FrameRate frameRate}) {
  num? fps;
  if (frameRate == FrameRate.max) {
    return progress;
  } else if (frameRate == FrameRate.composition) {
    fps = this.frameRate;
  }
  fps ??= frameRate.framesPerSecond;
  assert(!fps.isNaN && fps.isFinite && !fps.isNegative);

  var noOffsetDurationFrames = durationFrames + 0.01;
  var totalFrameCount = (noOffsetDurationFrames / this.frameRate) * fps;
  var frameIndex = (totalFrameCount * progress).toInt();
  var roundedProgress = frameIndex / totalFrameCount;
  assert(roundedProgress >= 0 && roundedProgress <= 1,
      'Progress is $roundedProgress');
  return roundedProgress;
}