when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String id,
- String token,
- LocatorMqttConfig? mqttConfig,
- List<
Asset> ? assets, - List<
String> ? assetsIds, - List<
Geofence> ? geofences, - List<
String> ? geofencesIds, - List<
Trigger> ? triggers, - List<
String> ? triggersIds, - DateTime? expiresAt,
- User? expiredBy,
- String? expiredById,
- bool? isExpired,
- DateTime createdAt,
- User? createdBy,
- String? createdById,
- DateTime updatedAt,
- User? updatedBy,
- String? updatedById,
- RegisteredApp? customization,
- String? customizationId,
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 token, LocatorMqttConfig? mqttConfig, List<Asset>? assets, List<String>? assetsIds, List<Geofence>? geofences, List<String>? geofencesIds, List<Trigger>? triggers, List<String>? triggersIds, @TimestampOrNullConverter() DateTime? expiresAt, User? expiredBy, String? expiredById, bool? isExpired, @TimestampConverter() DateTime createdAt, User? createdBy, String? createdById, @TimestampConverter() DateTime updatedAt, User? updatedBy, String? updatedById, RegisteredApp? customization, String? customizationId) $default,) {final _that = this;
switch (_that) {
case _Locator():
return $default(_that.id,_that.token,_that.mqttConfig,_that.assets,_that.assetsIds,_that.geofences,_that.geofencesIds,_that.triggers,_that.triggersIds,_that.expiresAt,_that.expiredBy,_that.expiredById,_that.isExpired,_that.createdAt,_that.createdBy,_that.createdById,_that.updatedAt,_that.updatedBy,_that.updatedById,_that.customization,_that.customizationId);case _:
throw StateError('Unexpected subclass');
}
}