toBool property
bool
get
toBool
Converts the string to a boolean value.
The string is trimmed and converted to lowercase. It returns true
if the string is
'1' or 'true', and false
for any other value.
Example:
var strTrue = 'true';
var strOne = '1';
var strFalse = 'false';
print(strTrue.toBool); // Outputs: true
print(strOne.toBool); // Outputs: true
print(strFalse.toBool); // Outputs: false
Returns true
if the string is '1' or 'true', otherwise false
.
Implementation
bool get toBool {
String value = trim().toLowerCase();
if (value == "1") {
return true;
}
if (value == 'true') {
return true;
}
return false;
}