Skip to content

Bool Extension

isTrue & isFalse (null safety)

Checks if the Boolean values considering null safety.

dart
bool? flag = true;
print(flag.isTrue);  // Output: true

bool? flag2 = null;
print(flag.isFalse);  // Output: false
print(flag.isNull); // Output: true
bool? flag = true;
print(flag.isTrue);  // Output: true

bool? flag2 = null;
print(flag.isFalse);  // Output: false
print(flag.isNull); // Output: true

val

Returns the Boolean value or false if it is null.

dart
bool? flag = null;
print(flag.val);  // Output: false
bool? flag = null;
print(flag.val);  // Output: false

binary

Returns 1 if the Boolean is true and zero if it is false or null.

dart
bool? flag = true;
print(flag.binary);  // Output: 1
bool? flag = true;
print(flag.binary);  // Output: 1

binaryText

Returns '1' if the Boolean is true and '0' if it is false or null.

dart
bool? flag = false;
print(flag.binaryText);  // Output: 0
bool? flag = false;
print(flag.binaryText);  // Output: 0