toBool method

bool toBool({
  1. bool def = false,
})

Try to parse to bool, fallback to def

Implementation

bool toBool({bool def = false}) {
  if (this == null) return def;
  final value = toString().toLowerCase();
  if (value == 'true' || value == '1') return true;
  if (value == 'false' || value == '0') return false;
  return def;
}