toBool method

bool toBool([
  1. bool defaultValue = false
])

Converts String to bool.

If the string cannot be converted, defaultValue is returned.

Stringboolに変換します。

変換できない文字列の場合、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;
}