orZero method

int orZero()

Returns the integer value or 0 if the value is null.

Useful when a nullable int might be null, and you want a default value.

Example:

int? value = null;
print(value.orZero()); // 0

Implementation

int orZero() {
  return this ?? 0;
}