toBool property
bool
toBool
Checks the String
and maps the value to a bool
if possible.
Example
String text = 'yes';
bool? textBool = text.toBool ; // returns true
Implementation
bool get toBool {
if (this.isBlank) {
throw Exception("Can't convert empty string to bool");
}
if (this.toLowerCase() == 'true' || this.toLowerCase() == 'yes') {
return true;
}
if (this.toLowerCase() == 'false' || this.toLowerCase() == 'no') {
return false;
}
throw Exception("Can't convert string to bool");
}