toBool function Null safety

bool toBool(
  1. dynamic val
)

Converts any val to boolean int != 0 null => false bool => val tries: val.isNotEmpty if has no getter isNotEmpty => true

Implementation

bool toBool(val) {
  if (val is bool) {
    return val;
  }
  if (val == null) {
    return false;
  }
  if (val is num) {
    return val != 0;
  }
  // For strings|iterables
  // <editor-fold desc="Is not empty">
  try {
    return val.isNotEmpty;
  } on NoSuchMethodError {
    // Pass
  }
  // </editor-fold>
  return true;
}