whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String id,
    2. String name,
    3. Map<String, dynamic>? credentials,
    4. OutboundProtocol? protocol,
    5. String? protocolId,
    6. bool? isEnabled,
    7. List<OutboundStructure>? structure,
    8. String? token,
    9. List<String>? assetsIds,
    10. List<Asset>? assets,
    11. List<String>? groupsIds,
    12. List<Tag>? groups,
    13. List<Access>? access,
    14. OutboundMetrics? metrics,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id,  String name,  Map<String, dynamic>? credentials,  OutboundProtocol? protocol,  String? protocolId,  bool? isEnabled,  List<OutboundStructure>? structure,  String? token,  List<String>? assetsIds,  List<Asset>? assets,  List<String>? groupsIds,  List<Tag>? groups,  List<Access>? access,  OutboundMetrics? metrics)?  $default,) {final _that = this;
switch (_that) {
case _OutboundService() when $default != null:
return $default(_that.id,_that.name,_that.credentials,_that.protocol,_that.protocolId,_that.isEnabled,_that.structure,_that.token,_that.assetsIds,_that.assets,_that.groupsIds,_that.groups,_that.access,_that.metrics);case _:
  return null;

}
}