toBoolean function

bool toBoolean(
  1. String str, [
  2. bool strict = false
])

convert the input to a boolean.

Everything except for '0', 'false' and '' returns true. In strict mode only '1' and 'true' return true.

Implementation

bool toBoolean(String str, [bool strict = false]) {
  if (strict == true) {
    return str == '1' || str == 'true';
  }
  return str != '0' && str != 'false' && str != '';
}