whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. List<ConfigSource>? sources,
    2. String parameter,
    3. String? description,
    4. ConfigPayloadDataType? dataType,
    5. num? minValue,
    6. num? maxValue,
    7. int? minLength,
    8. int? maxLength,
    9. List<String>? choices,
    10. RegExp? regexPattern,
    11. bool? setupCapable,
    )?
)

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(@JsonKey(unknownEnumValue: ConfigSource.unknown)  List<ConfigSource>? sources,  String parameter,  String? description, @JsonKey(unknownEnumValue: ConfigPayloadDataType.unknown)  ConfigPayloadDataType? dataType,  num? minValue,  num? maxValue,  int? minLength,  int? maxLength,  List<String>? choices, @RegExpOrNullConverter()  RegExp? regexPattern,  bool? setupCapable)?  $default,) {final _that = this;
switch (_that) {
case _ConfigDefinition() when $default != null:
return $default(_that.sources,_that.parameter,_that.description,_that.dataType,_that.minValue,_that.maxValue,_that.minLength,_that.maxLength,_that.choices,_that.regexPattern,_that.setupCapable);case _:
  return null;

}
}