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()? none,
TResult? Function(bool field0)? boolean,
TResult? Function(PlatformInt64 field0)? integer,
TResult? Function(double field0)? float,
TResult? Function(String field0)? bigint,
TResult? Function(String field0)? string,
TResult? Function(List<JsValue> field0)? array,
TResult? Function(Map<String, JsValue> field0)? object,
}) {
final _that = this;
switch (_that) {
case JsValue_None() when none != null:
return none();
case JsValue_Boolean() when boolean != null:
return boolean(_that.field0);
case JsValue_Integer() when integer != null:
return integer(_that.field0);
case JsValue_Float() when float != null:
return float(_that.field0);
case JsValue_Bigint() when bigint != null:
return bigint(_that.field0);
case JsValue_String() when string != null:
return string(_that.field0);
case JsValue_Array() when array != null:
return array(_that.field0);
case JsValue_Object() when object != null:
return object(_that.field0);
case _:
return null;
}
}