percentageOf method

double percentageOf(
  1. Duration total
)

Returns this duration as a percentage (0.0–1.0+) of total.

const Duration(minutes: 30).percentageOf(const Duration(hours: 1)) // 0.5

Implementation

double percentageOf(Duration total) {
  if (total.inMicroseconds == 0) return 0;
  return inMicroseconds / total.inMicroseconds;
}