when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String name,
    3. String? flespiId,
    4. InboundProtocol? protocol,
    5. String? protocolId,
    6. bool? isGeneric,
    7. List<CommandDefinition> commandsStructure,
    8. List<ConfigGrouping> configStructure,
    9. bool confiotCapable,
    10. ConfIoTLayout confiotLayout,
    11. String? confiotName,
    12. String? peripheralIdentifier,
    13. Map<String, dynamic>? peripheralParserSpec,
    14. List<FirmwareBuild> firmwares,
    )
)

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,  String? flespiId,  InboundProtocol? protocol,  String? protocolId,  bool? isGeneric,  List<CommandDefinition> commandsStructure,  List<ConfigGrouping> configStructure,  bool confiotCapable, @JsonKey(unknownEnumValue: ConfIoTLayout.standard)  ConfIoTLayout confiotLayout,  String? confiotName,  String? peripheralIdentifier,  Map<String, dynamic>? peripheralParserSpec,  List<FirmwareBuild> firmwares)  $default,) {final _that = this;
switch (_that) {
case _Model():
return $default(_that.id,_that.name,_that.flespiId,_that.protocol,_that.protocolId,_that.isGeneric,_that.commandsStructure,_that.configStructure,_that.confiotCapable,_that.confiotLayout,_that.confiotName,_that.peripheralIdentifier,_that.peripheralParserSpec,_that.firmwares);case _:
  throw StateError('Unexpected subclass');

}
}