coerceSemanticBool function
Reads value as a bool, or null if it isn't one. Accepts a real bool, a
num (0 ⇒ false, else true), and the common string spellings an agent
might emit ("true", "on", "1", "checked", …), case-insensitively.
Implementation
bool? coerceSemanticBool(Object? value) {
if (value is bool) return value;
if (value is num) return value != 0;
if (value is String) {
switch (value.trim().toLowerCase()) {
case 'true' || '1' || 'yes' || 'on' || 'checked' || 'enabled':
return true;
case 'false' || '0' || 'no' || 'off' || 'unchecked' || 'disabled':
return false;
}
}
return null;
}