isBool function

bool isBool(
  1. dynamic b, {
  2. List<String> allow = const ['true', 'false', '1', '0', 'yes', 'no'],
})

Dynamic check for a boolean from a String/bool

Implementation

bool isBool(dynamic b,
    {List<String> allow = const ['true', 'false', '1', '0', 'yes', 'no']}) {
  try {
    if (b == null) return false;
    if (b is bool) return true;
    b = b.toString().trim().toLowerCase();
    return allow.contains(b);
  } catch (e) {
    return false;
  }
}