toBool method

bool? toBool()

Parses boolean-ish strings: true/yes/1/y -> true, false/no/0/n -> false, otherwise null.

Implementation

bool? toBool() {
  switch (trim().toLowerCase()) {
    case 'true':
    case 'yes':
    case '1':
    case 'y':
      return true;
    case 'false':
    case 'no':
    case '0':
    case 'n':
      return false;
    default:
      return null;
  }
}