parseBooleanValue static method
The value of a boolean attribute (isBooleanAttribute) attrName: the
one rule for every way a value comes in (parsed HTML, a template, a
bool, setValue, a generator's setAttribute).
parseBooleanValue('checked', ''); // true: <input checked>
parseBooleanValue('checked', 'checked'); // true: XHTML form
parseBooleanValue('checked', 'true'); // true (also on, yes, 1)
parseBooleanValue('checked', 'false'); // false (also off, no, 0)
parseBooleanValue('checked', true); // true
parseBooleanValue('checked', null); // false: no value
Implementation
static bool parseBooleanValue(String? attrName, Object? value) {
if (value == null) return false;
if (value is bool) return value;
if (value is String) {
var s = value.trim();
if (s.isEmpty) return true;
if (attrName != null && s.toLowerCase() == attrName) return true;
return parseBool(s, false)!;
}
return parseBool(value, false)!;
}