asBoolOrFalse method

bool asBoolOrFalse()

Returns the picked value as bool or defaults to false when the value is null or can't be interpreted as bool.

Only the exact Strings "true" and "false" are valid boolean representations. Other concepts of booleans such as 1 and 0, or "YES" and "NO" are not supported.

Use .let() to parse those custom representations

pick(1).letOrNull((pick) {
   if (pick.value == 1) {
     return true;
   }
   if (pick.value == 0) {
     return false;
   }
   return null;
 });

Implementation

bool asBoolOrFalse() {
  if (value == null) return false;
  try {
    return _parse();
  } catch (_) {
    return false;
  }
}