tryPlus method

  1. @useResult
Offset? tryPlus({
  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 added.

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

Offset(16).tryPlus(hours: 2); // Offset(18)

Offset(18).tryPlus(hours: 2); // null

Implementation

@useResult Offset? tryPlus({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;
  }
}