whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? none()?,
- TResult? boolean(
- bool field0
- TResult? integer(
- PlatformInt64 field0
- TResult? float(
- double field0
- TResult? bigint(
- String field0
- TResult? string(
- String field0
- TResult? bytes(
- Uint8List field0
- TResult? array()?,
- TResult? object()?,
- TResult? date(
- PlatformInt64 field0
- TResult? symbol(
- String field0
- TResult? function(
- String field0
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( Uint8List field0)? bytes,TResult? Function( List<JsValue> field0)? array,TResult? Function( Map<String, JsValue> field0)? object,TResult? Function( PlatformInt64 field0)? date,TResult? Function( String field0)? symbol,TResult? Function( String field0)? function,}) {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_Bytes() when bytes != null:
return bytes(_that.field0);case JsValue_Array() when array != null:
return array(_that.field0);case JsValue_Object() when object != null:
return object(_that.field0);case JsValue_Date() when date != null:
return date(_that.field0);case JsValue_Symbol() when symbol != null:
return symbol(_that.field0);case JsValue_Function() when function != null:
return function(_that.field0);case _:
return null;
}
}