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) {
return null;
}
if (this?.toLowerCase() == 'true' || this?.toLowerCase() == 'yes') {
return true;
}
if (this?.toLowerCase() == 'false' || this?.toLowerCase() == 'no') {
return false;
}
return null;
}