progressOf method

double progressOf(
  1. Duration total, {
  2. bool clampResult = true,
})

Returns a 0.0–1.0 progress value relative to total. Clamps to 0, 1 by default; pass clampResult = false to allow overflow.

Implementation

double progressOf(Duration total, {bool clampResult = true}) {
  if (total.isZero) return 0.0;
  final ratio = inMicroseconds / total.inMicroseconds;
  return clampResult ? ratio.clamp(0.0, 1.0) : ratio;
}