toBool function

bool? toBool(
  1. dynamic s, {
  2. List<String> allowTrue = const ['true', '1', 'yes'],
  3. List<String> allowFalse = const ['false', '0', 'no'],
})

Implementation

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