whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? legacy(
- MessageHeader header,
- List<
Ed25519HDPublicKey> accountKeys, - String recentBlockhash,
- List<
CompiledInstruction> instructions,
- TResult? v0(
- MessageHeader header,
- List<
Ed25519HDPublicKey> accountKeys, - String recentBlockhash,
- List<
CompiledInstruction> instructions, - 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;
}
}