NullableBoolX extension
Extension on bool? to add utility methods.
This extension provides two methods:
orFalse: a getter that returns the boolean if it's not null, otherwise it returns false.or: a method that returns the boolean if it's not null, otherwise it returns a default value.
Example usage:
bool? nullableBool = null;
print(nullableBool.orFalse); // Outputs: false
print(nullableBool.or(defaultValue: true)); // Outputs: true
nullableBool = true;
print(nullableBool.orFalse); // Outputs: true
print(nullableBool.or(defaultValue: false)); // Outputs: true
- on
-
- bool?
Properties
- orFalse → bool
-
Available on bool?, provided by the NullableBoolX extension
Returns the boolean if it's not null, otherwise it returns false.no setter
Methods
-
or(
{bool defaultValue = false}) → bool -
Available on bool?, provided by the NullableBoolX extension
Returns the boolean if it's not null, otherwise it returns a default value.