whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
  1. TResult? openUrl(
    1. String url,
    2. String label,
    3. bool openInApp,
    4. String style,
    )?,
  2. TResult? sendMessage(
    1. String message,
    2. String label,
    3. bool showInChat,
    4. String style,
    )?,
  3. TResult? callback(
    1. String callbackId,
    2. String label,
    3. Map<String, dynamic>? payload,
    4. String style,
    )?,
})

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( String url,  String label, @JsonKey(name: 'open_in_app')  bool openInApp,  String style)?  openUrl,TResult? Function( String message,  String label, @JsonKey(name: 'show_in_chat')  bool showInChat,  String style)?  sendMessage,TResult? Function(@JsonKey(name: 'callback_id')  String callbackId,  String label,  Map<String, dynamic>? payload,  String style)?  callback,}) {final _that = this;
switch (_that) {
case OpenUrlAction() when openUrl != null:
return openUrl(_that.url,_that.label,_that.openInApp,_that.style);case SendMessageAction() when sendMessage != null:
return sendMessage(_that.message,_that.label,_that.showInChat,_that.style);case CallbackAction() when callback != null:
return callback(_that.callbackId,_that.label,_that.payload,_that.style);case _:
  return null;

}
}