whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String $type,
    2. String key,
    3. String did,
    4. Map<String, dynamic> value,
    5. String? description,
    6. DateTime? createdAt,
    7. DateTime? updatedAt,
    8. OptionManagerRole? managerRole,
    9. OptionScope scope,
    10. String createdBy,
    11. String lastUpdatedBy,
    12. Map<String, dynamic>? $unknown,
    )?
)

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 $type,  String key,  String did,  Map<String, dynamic> value,  String? description,  DateTime? createdAt,  DateTime? updatedAt, @OptionManagerRoleConverter()  OptionManagerRole? managerRole, @OptionScopeConverter()  OptionScope scope,  String createdBy,  String lastUpdatedBy,  Map<String, dynamic>? $unknown)?  $default,) {final _that = this;
switch (_that) {
case _Option() when $default != null:
return $default(_that.$type,_that.key,_that.did,_that.value,_that.description,_that.createdAt,_that.updatedAt,_that.managerRole,_that.scope,_that.createdBy,_that.lastUpdatedBy,_that.$unknown);case _:
  return null;

}
}