whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? error(
- Error error
- TResult? block(
- BlockMsgType msgType,
- String blockHash,
- int blockHeight,
- Int64 blockTimestamp,
- CoinbaseData? coinbaseData,
- TResult? tx(
- TxMsgType msgType,
- String txid,
- TxFinalizationReasonType? finalizationReasonType
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( pb.Error error)? error,TResult? Function( BlockMsgType msgType, String blockHash, int blockHeight, Int64 blockTimestamp, pb.CoinbaseData? coinbaseData)? block,TResult? Function( TxMsgType msgType, String txid, TxFinalizationReasonType? finalizationReasonType)? tx,}) {final _that = this;
switch (_that) {
case WsErrorMsg() when error != null:
return error(_that.error);case WsMsgBlockClient() when block != null:
return block(_that.msgType,_that.blockHash,_that.blockHeight,_that.blockTimestamp,_that.coinbaseData);case WsMsgTxClient() when tx != null:
return tx(_that.msgType,_that.txid,_that.finalizationReasonType);case _:
return null;
}
}