when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default()
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? fromAssetId, Asset? fromAsset, String? sensorId, Sensor? sensor, String? toAssetId, Asset? toAsset, double? totalLiters, @TimestampOrNullConverter() DateTime? startAt, @TimestampOrNullConverter() DateTime? endAt, bool? isReady, bool? inProgress, bool? isValidated) $default,) {final _that = this;
switch (_that) {
case _AtsPossibleExit():
return $default(_that.id,_that.fromAssetId,_that.fromAsset,_that.sensorId,_that.sensor,_that.toAssetId,_that.toAsset,_that.totalLiters,_that.startAt,_that.endAt,_that.isReady,_that.inProgress,_that.isValidated);case _:
throw StateError('Unexpected subclass');
}
}