when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult openUrl(
    1. String url,
    2. String label,
    3. @JsonKey.new(name: 'open_in_app') bool openInApp,
    4. String style,
    ),
  2. required TResult sendMessage(
    1. String message,
    2. String label,
    3. @JsonKey.new(name: 'show_in_chat') bool showInChat,
    4. String style,
    ),
  3. required TResult callback(
    1. @JsonKey.new(name: 'callback_id') String callbackId,
    2. String label,
    3. Map<String, dynamic>? payload,
    4. String style,
    ),
})

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);}
}