toBool method
If the string cannot be converted, defaultValue
is returned.
変換できない文字列の場合、defaultValue
が返されます。
final text = "True";
final boolValue = text.toBool(); // true
final text = "false";
final boolValue = text.toBool(); // false
final text = "TRUE";
final boolValue = text.toBool(); // true
Implementation
bool toBool([bool defaultValue = false]) {
if (toLowerCase() == "true") {
return true;
} else if (toLowerCase() == "false") {
return false;
}
return defaultValue;
}