whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
A variant of when that fallback to returning null
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String field0)? str,
TResult? Function(PlatformInt64 field0)? int,
TResult? Function(double field0)? float,
TResult? Function(bool field0)? bool,
TResult? Function(List<String> field0)? listStr,
TResult? Function(Int64List field0)? listInt,
}) {
final _that = this;
switch (_that) {
case PyArgument_Str() when str != null:
return str(_that.field0);
case PyArgument_Int() when int != null:
return int(_that.field0);
case PyArgument_Float() when float != null:
return float(_that.field0);
case PyArgument_Bool() when bool != null:
return bool(_that.field0);
case PyArgument_ListStr() when listStr != null:
return listStr(_that.field0);
case PyArgument_ListInt() when listInt != null:
return listInt(_that.field0);
case _:
return null;
}
}