NullableIntX extension
Extension on int? to add utility methods.
This extension provides two methods:
orZero: a getter that returns the integer if it's not null, otherwise it returns zero.or: a method that returns the integer if it's not null, otherwise it returns a default value.
Example usage:
int? nullableInt = null;
print(nullableInt.orZero); // Outputs: 0
print(nullableInt.or(defaultValue: 5)); // Outputs: 5
nullableInt = 10;
print(nullableInt.orZero); // Outputs: 10
print(nullableInt.or(defaultValue: 5)); // Outputs: 10
- on
-
- int?
Properties
- orZero → int
-
Available on int?, provided by the NullableIntX extension
Returns the integer if it's not null, otherwise it returns zero.no setter
Methods
-
isNegativeValue(
) → bool -
Available on int?, provided by the NullableIntX extension
Checks if the integer is negative. -
isPositive(
) → bool -
Available on int?, provided by the NullableIntX extension
Checks if the integer is positive. -
or(
{int defaultValue = 0}) → int -
Available on int?, provided by the NullableIntX extension
Returns the integer if it's not null, otherwise it returns a default value.