when<TResult extends Object?> method
TResult
when<TResult extends Object?>({})
A switch-like method, using callbacks.
As opposed to map, this offers destructuring.
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case Subclass2(:final field2):
return ...;
}
Implementation
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function( String url, String label, @JsonKey(name: 'open_in_app') bool openInApp, String style) openUrl,required TResult Function( String message, String label, @JsonKey(name: 'show_in_chat') bool showInChat, String style) sendMessage,required TResult Function(@JsonKey(name: 'callback_id') String callbackId, String label, Map<String, dynamic>? payload, String style) callback,}) {final _that = this;
switch (_that) {
case OpenUrlAction():
return openUrl(_that.url,_that.label,_that.openInApp,_that.style);case SendMessageAction():
return sendMessage(_that.message,_that.label,_that.showInChat,_that.style);case CallbackAction():
return callback(_that.callbackId,_that.label,_that.payload,_that.style);}
}