when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String name,
    3. Color color,
    4. bool isEnabled,
    5. List<String> categoriesIds,
    6. bool? hasFtp,
    7. bool? isConsumpted,
    8. String? mqttTopic,
    9. bool? isAsync,
    10. List<CredentialField> requiredFields,
    11. Avatar? dynamicIcon,
    12. int? usage,
    )
)

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

}
}