asBool property

bool asBool

Convert this string into boolean.

Returns true if this string is any of these values: "true", "yes", "1", or if the string is a number and greater than 0, false if less than 1. This is also case insensitive.

Implementation

bool get asBool {
  var s = this?.trim().toLowerCase() ?? "false";
  num n;
  try {
    n = num.parse(s);
  } catch (e) {
    n = -1;
  }
  return s == 'true' || s == 'yes' || n > 0;
}