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;

  var totalFrameCount = seconds * fps;
  var frameIndex = (totalFrameCount * progress).toInt();
  var roundedProgress = frameIndex / totalFrameCount;
  assert(roundedProgress >= 0 && roundedProgress <= 1,
      'Progress is $roundedProgress');
  return roundedProgress;
}