when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String id,
- String name,
- String ident,
- String? flespiToken,
- String? modelId,
- Model? model,
- String? protocolId,
- InboundProtocol? protocol,
- Map<
String, dynamic> ? additionalFields, - String? qrCode,
- String? linkQr,
- List<
DeviceCommand> ? commands, - List<
Access> ? access, - DeviceTelemetry? telemetry,
- String? visionProfileId,
- VisionProfile? visionProfile,
- PhoneNumber? phone,
- ModbusConfig? modbus,
- bool? isSuspended,
- HwModel? hwModel,
- String? hwModelId,
- String? macAddress,
- Map<
String, dynamic> ? configParams, - Duration? visionCaptureThreshold,
- List<
Device> ? peripherals, - String? localIpAddress,
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 ident, String? flespiToken, String? modelId, Model? model, String? protocolId, InboundProtocol? protocol, Map<String, dynamic>? additionalFields, String? qrCode, String? linkQr, List<DeviceCommand>? commands, List<Access>? access, DeviceTelemetry? telemetry, String? visionProfileId, VisionProfile? visionProfile, PhoneNumber? phone, ModbusConfig? modbus, bool? isSuspended, HwModel? hwModel, String? hwModelId, String? macAddress, Map<String, dynamic>? configParams, @DurationConverter() Duration? visionCaptureThreshold, List<Device>? peripherals, String? localIpAddress) $default,) {final _that = this;
switch (_that) {
case _Device():
return $default(_that.id,_that.name,_that.ident,_that.flespiToken,_that.modelId,_that.model,_that.protocolId,_that.protocol,_that.additionalFields,_that.qrCode,_that.linkQr,_that.commands,_that.access,_that.telemetry,_that.visionProfileId,_that.visionProfile,_that.phone,_that.modbus,_that.isSuspended,_that.hwModel,_that.hwModelId,_that.macAddress,_that.configParams,_that.visionCaptureThreshold,_that.peripherals,_that.localIpAddress);case _:
throw StateError('Unexpected subclass');
}
}