whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
  1. TResult? transfer(
    1. ParsedSystemTransferInformation info,
    2. String type
    )?,
  2. TResult? transferChecked(
    1. ParsedSystemTransferInformation info,
    2. String type
    )?,
  3. TResult? unsupported(
    1. String type
    )?,
})

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( ParsedSystemTransferInformation info,  String type)?  transfer,TResult? Function( ParsedSystemTransferInformation info,  String type)?  transferChecked,TResult? Function( String type)?  unsupported,}) {final _that = this;
switch (_that) {
case ParsedSystemTransferInstruction() when transfer != null:
return transfer(_that.info,_that.type);case ParsedSystemTransferCheckedInstruction() when transferChecked != null:
return transferChecked(_that.info,_that.type);case ParsedSystemUnsupportedInstruction() when unsupported != null:
return unsupported(_that.type);case _:
  return null;

}
}