whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. int? id,
    2. String? name,
    3. String? location,
    4. double? latitude,
    5. double? longitude,
    6. int? businessUnitId,
    7. int? depotTypeId,
    8. int? depotStatus,
    9. BusinessUnit? businessUnit,
    10. DepotType? depotType,
    11. InternalArea? internalArea,
    12. int? internalAreaId,
    13. DateTime? createdDate,
    14. String? cluster,
    15. String? internalRegion,
    )?
)

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( int? id,  String? name,  String? location,  double? latitude,  double? longitude,  int? businessUnitId,  int? depotTypeId,  int? depotStatus,  BusinessUnit? businessUnit,  DepotType? depotType,  InternalArea? internalArea,  int? internalAreaId,  DateTime? createdDate,  String? cluster,  String? internalRegion)?  $default,) {final _that = this;
switch (_that) {
case _Depot() when $default != null:
return $default(_that.id,_that.name,_that.location,_that.latitude,_that.longitude,_that.businessUnitId,_that.depotTypeId,_that.depotStatus,_that.businessUnit,_that.depotType,_that.internalArea,_that.internalAreaId,_that.createdDate,_that.cluster,_that.internalRegion);case _:
  return null;

}
}