whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
  1. TResult? legacy(
    1. MessageHeader header,
    2. List<Ed25519HDPublicKey> accountKeys,
    3. String recentBlockhash,
    4. List<CompiledInstruction> instructions,
    )?,
  2. TResult? v0(
    1. MessageHeader header,
    2. List<Ed25519HDPublicKey> accountKeys,
    3. String recentBlockhash,
    4. List<CompiledInstruction> instructions,
    5. List<MessageAddressTableLookup> addressTableLookups,
    )?,
})

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( MessageHeader header,  List<Ed25519HDPublicKey> accountKeys,  String recentBlockhash,  List<CompiledInstruction> instructions)?  legacy,TResult? Function( MessageHeader header,  List<Ed25519HDPublicKey> accountKeys,  String recentBlockhash,  List<CompiledInstruction> instructions,  List<MessageAddressTableLookup> addressTableLookups)?  v0,}) {final _that = this;
switch (_that) {
case CompiledMessageLegacy() when legacy != null:
return legacy(_that.header,_that.accountKeys,_that.recentBlockhash,_that.instructions);case CompiledMessageV0() when v0 != null:
return v0(_that.header,_that.accountKeys,_that.recentBlockhash,_that.instructions,_that.addressTableLookups);case _:
  return null;

}
}