isBool method

bool isBool({
  1. bool caseSensitive = true,
})

Checks if the string represents a boolean value.

If caseSensitive is true (default), it only accepts "true" and "false".

Example:

print('true'.isBool()); // true
print('false'.isBool()); // true
print('TRUE'.isBool()); // false
print('TRUE'.isBool(caseSensitive: false)); // true

Implementation

bool isBool({bool caseSensitive = true}) {
  final lowerCaseValue = caseSensitive ? this : toLowerCase();
  return lowerCaseValue == 'true' || lowerCaseValue == 'false';
}