parseBool function

bool? parseBool(
  1. Object? v, [
  2. bool? def
])

Implementation

bool? parseBool(Object? v, [bool? def]) {
  if (v == null) return def;

  if (v is bool) return v;

  if (v is num) return v > 0;

  String s;
  if (v is String) {
    s = v;
  } else {
    s = v.toString();
  }

  s = s.trim().toLowerCase();

  if (s.isEmpty) return def;

  return s == 'true' ||
      s == 'yes' ||
      s == 'ok' ||
      s == '1' ||
      s == 'y' ||
      s == 's' ||
      s == 't' ||
      s == '+';
}