asBoolOrThrow method
Returns the picked value as bool or throws a PickException
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 asBoolOrThrow() {
withContext(
requiredPickErrorHintKey,
'Use asBoolOrNull() when the value may be null/absent at some point (bool?).',
);
return _parse();
}