whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? blocking()?,
- TResult? blockedBy()?,
- TResult? blockOther()?,
- TResult? label(
- ModerationCauseLabel data
- TResult? muted(
- ModerationCauseMuted data
- TResult? muteWord()?,
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( ModerationCauseBlocking data)? blocking,TResult? Function( ModerationCauseBlockedBy data)? blockedBy,TResult? Function( ModerationCauseBlockOther data)? blockOther,TResult? Function( ModerationCauseLabel data)? label,TResult? Function( ModerationCauseMuted data)? muted,TResult? Function( ModerationCauseMuteWord data)? muteWord,TResult? Function( ModerationCauseHidden data)? hidden,}) {final _that = this;
switch (_that) {
case UModerationCauseBlocking() when blocking != null:
return blocking(_that.data);case UModerationCauseBlockedBy() when blockedBy != null:
return blockedBy(_that.data);case UModerationCauseBlockOther() when blockOther != null:
return blockOther(_that.data);case UModerationCauseLabel() when label != null:
return label(_that.data);case UModerationCauseMuted() when muted != null:
return muted(_that.data);case UModerationCauseMuteWord() when muteWord != null:
return muteWord(_that.data);case UModerationCauseHidden() when hidden != null:
return hidden(_that.data);case _:
return null;
}
}