toBool method

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

Converts the string into a boolean value.

Throws an error if the string is not "true" or "false".

Example:

print('true'.toBool()); // true
print('false'.toBool()); // false

Implementation

bool toBool({bool caseSensitive = true}) {
  if (!isBool(caseSensitive: caseSensitive)) {
    throw FormatException('Invalid boolean value: $this');
  }
  return (caseSensitive ? this : toLowerCase()) == 'true';
}