when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String from,
    3. DateTime timestamp,
    4. String? text,
    5. MessageType messageType,
    6. String? attachmentUrl,
    7. String? referencedMessageId,
    8. String? clientMessageId,
    9. String? reaction,
    10. String? reply,
    11. Map<String, dynamic>? metadata,
    12. ReceiptStatus? receipt,
    13. bool isEdited,
    14. bool isDeleted,
    15. bool isForwarded,
    16. bool isStarred,
    17. bool isSystem,
    18. String? mimeType,
    19. String? fileName,
    20. String? fileSize,
    21. String? thumbnailUrl,
    )
)

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?>(TResult Function( String id,  String from,  DateTime timestamp,  String? text,  MessageType messageType,  String? attachmentUrl,  String? referencedMessageId,  String? clientMessageId,  String? reaction,  String? reply,  Map<String, dynamic>? metadata,  ReceiptStatus? receipt,  bool isEdited,  bool isDeleted,  bool isForwarded,  bool isStarred,  bool isSystem,  String? mimeType,  String? fileName,  String? fileSize,  String? thumbnailUrl)  $default,) {final _that = this;
switch (_that) {
case _ChatMessage():
return $default(_that.id,_that.from,_that.timestamp,_that.text,_that.messageType,_that.attachmentUrl,_that.referencedMessageId,_that.clientMessageId,_that.reaction,_that.reply,_that.metadata,_that.receipt,_that.isEdited,_that.isDeleted,_that.isForwarded,_that.isStarred,_that.isSystem,_that.mimeType,_that.fileName,_that.fileSize,_that.thumbnailUrl);case _:
  throw StateError('Unexpected subclass');

}
}