asBool function

bool asBool(
  1. Object? value
)

Coerces a value to a truth for logical functions. A number is true when non-zero; the strings TRUE/FALSE (any case) map accordingly, empty is false, other text is true.

Implementation

bool asBool(Object? value) {
  if (value is bool) return value;
  if (value is num) return value != 0;
  if (value is String) {
    final t = value.trim().toUpperCase();
    if (t == 'TRUE') return true;
    if (t == 'FALSE' || t.isEmpty) return false;
    return true;
  }
  return false;
}