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?>(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');
}
}