whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>({
- TResult? openUrl()?,
- TResult? sendMessage()?,
- TResult? callback()?,
- TResult? requestInput()?,
- TResult? changeLanguage(
- String locale
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,TResult? Function(@JsonKey(name: 'input_type') String inputType, String label, String source, String style)? requestInput,TResult? Function( String locale)? changeLanguage,}) {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 RequestInputAction() when requestInput != null:
return requestInput(_that.inputType,_that.label,_that.source,_that.style);case ChangeLanguageAction() when changeLanguage != null:
return changeLanguage(_that.locale);case _:
return null;
}
}