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( String id, String name, @ColorConverter() Color color, bool isEnabled, List<String> categoriesIds, bool? hasFtp, bool? isConsumpted, String? mqttTopic, bool? isAsync, List<CredentialField> requiredFields, Avatar? dynamicIcon, int? usage) $default,) {final _that = this;
switch (_that) {
case _OutboundProtocol():
return $default(_that.id,_that.name,_that.color,_that.isEnabled,_that.categoriesIds,_that.hasFtp,_that.isConsumpted,_that.mqttTopic,_that.isAsync,_that.requiredFields,_that.dynamicIcon,_that.usage);case _:
throw StateError('Unexpected subclass');
}
}