asBoolOrTrue method
Returns the picked value as bool or defaults to true
when the
value is null
or can't be interpreted as bool.
Only the exact Strings "true" and "false" are valid boolean
representations. Other concepts of booleans such as 1
and 0
,
or "YES" and "NO" are not supported.
Use .let()
to parse those custom representations
pick(1).letOrNull((pick) {
if (pick.value == 1) {
return true;
}
if (pick.value == 0) {
return false;
}
return null;
});
Implementation
bool asBoolOrTrue() {
if (value == null) return true;
try {
return _parse();
} catch (_) {
return true;
}
}