scaleByCoefficient method

Duration scaleByCoefficient([
  1. double coefficient = 1.0
])

Decreases the current duration value by a percentage of its value. Example: Current value: hours: 1, minutes: 30, seconds: 20, milliseconds: 500 coefficient: 0.5 Resulting value: hours: 0, minutes: 45, seconds: 10, milliseconds: 250

Implementation

Duration scaleByCoefficient([double coefficient = 1.0]) {
  // Ensure the coefficient is between 0.0 and 1.0
  assert(coefficient >= 0.0 && coefficient <= 1.0,
      'Coefficient must be between 0.0 and 1.0');

  // Calculate the total duration in milliseconds
  final totalMilliseconds = this?.inMilliseconds ?? 0;

  // Calculate the new duration by multiplying with the coefficient
  final newMilliseconds = (totalMilliseconds * coefficient).toInt();

  // Return the new duration
  return Duration(milliseconds: newMilliseconds);
}