toBoolSafe method

bool toBoolSafe({
  1. bool defaultValue = false,
})

Implementation

bool toBoolSafe({bool defaultValue = false}) {
  if (this == null) return defaultValue;
  final val = this!.trim().toLowerCase();
  if (val == 'true' || val == '1') return true;
  if (val == 'false' || val == '0') return false;
  return defaultValue;
}