tryMinus method

  1. @useResult
Offset? tryMinus({
  1. int hours = 0,
  2. int minutes = 0,
  3. int seconds = 0,
})

Returns a copy of this with the sum of the units of time subtracted.

Otherwise returns null if the result is outside the valid range.

Offset(-16).tryMinus(hours: 2); // Offset(-18)

Offset(-18).tryMinus(hours: 2); // null

Implementation

@useResult Offset? tryMinus({int hours = 0, int minutes = 0, int seconds = 0}) {
  final total = _microseconds - sumMicroseconds(hours, minutes, seconds);
  if (-18 * Duration.microsecondsPerHour <= total && total <= 18 * Duration.microsecondsPerHour) {
    return Offset.fromMicroseconds(total);
  } else {
    return null;
  }
}