when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. bool enabled,
    2. double volume,
    3. bool messageSent,
    4. bool messageReceived,
    5. bool chatOpened,
    6. bool chatClosed,
    7. bool error,
    8. bool buttonClick,
    9. bool notification,
    10. String? messageSentSoundUrl,
    11. String? messageReceivedSoundUrl,
    12. String? notificationSoundUrl,
    13. String? errorSoundUrl,
    )
)

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( bool enabled,  double volume,  bool messageSent,  bool messageReceived,  bool chatOpened,  bool chatClosed,  bool error,  bool buttonClick,  bool notification,  String? messageSentSoundUrl,  String? messageReceivedSoundUrl,  String? notificationSoundUrl,  String? errorSoundUrl)  $default,) {final _that = this;
switch (_that) {
case _SoundConfiguration():
return $default(_that.enabled,_that.volume,_that.messageSent,_that.messageReceived,_that.chatOpened,_that.chatClosed,_that.error,_that.buttonClick,_that.notification,_that.messageSentSoundUrl,_that.messageReceivedSoundUrl,_that.notificationSoundUrl,_that.errorSoundUrl);case _:
  throw StateError('Unexpected subclass');

}
}