when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. @JsonKey.new(name: r'$ref') String? ref,
    2. String? type,
    3. String? format,
    4. String? title,
    5. String? description,
    6. @JsonKey.new(name: 'required') List<String>? $required,
    7. Map<String, Schema>? properties,
    8. Schema? items,
    9. dynamic example,
    10. @JsonKey.new(name: 'enum') List? enumValues,
    11. @JsonKey.new(name: 'default') dynamic $default,
    12. Xml? xml,
    13. @JsonKey.new(includeFromJson: false, includeToJson: false) dynamic additionalProperties,
    14. num? maximum,
    15. num? exclusiveMaximum,
    16. num? minimum,
    17. num? exclusiveMinimum,
    18. bool? readOnly,
    19. bool? writeOnly,
    20. ExternalDocs? externalDocs,
    21. Discriminator? discriminator,
    22. List<Schema>? allOf,
    23. List<Schema>? oneOf,
    24. List<Schema>? anyOf,
    25. Schema? not,
    26. bool? nullable,
    27. bool? allowEmptyValue,
    28. String? collectionFormat,
    29. int? maxLength,
    30. int? minLength,
    31. int? maxItems,
    32. int? minItems,
    33. String? pattern,
    34. bool? uniqueItems,
    35. int? maxProperties,
    36. int? minProperties,
    37. num? multipleOf,
    38. @JsonKey.new(name: 'deprecated') bool? $deprecated,
    39. @JsonKey.new(includeIfNull: false, includeFromJson: false, includeToJson: false) Map<String, dynamic>? extensions,
    )
)

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(@JsonKey(name: r'$ref')  String? ref,  String? type,  String? format,  String? title,  String? description, @JsonKey(name: 'required')  List<String>? $required,  Map<String, Schema>? properties,  Schema? items,  dynamic example, @JsonKey(name: 'enum')  List<dynamic>? enumValues, @JsonKey(name: 'default')  dynamic $default,  Xml? xml, @JsonKey(includeFromJson: false, includeToJson: false)  dynamic additionalProperties,  num? maximum,  num? exclusiveMaximum,  num? minimum,  num? exclusiveMinimum,  bool? readOnly,  bool? writeOnly,  ExternalDocs? externalDocs,  Discriminator? discriminator,  List<Schema>? allOf,  List<Schema>? oneOf,  List<Schema>? anyOf,  Schema? not,  bool? nullable,  bool? allowEmptyValue,  String? collectionFormat,  int? maxLength,  int? minLength,  int? maxItems,  int? minItems,  String? pattern,  bool? uniqueItems,  int? maxProperties,  int? minProperties,  num? multipleOf, @JsonKey(name: 'deprecated')  bool? $deprecated, @JsonKey(includeIfNull: false, includeFromJson: false, includeToJson: false)  Map<String, dynamic>? extensions)  $default,) {final _that = this;
switch (_that) {
case _Schema():
return $default(_that.ref,_that.type,_that.format,_that.title,_that.description,_that.$required,_that.properties,_that.items,_that.example,_that.enumValues,_that.$default,_that.xml,_that.additionalProperties,_that.maximum,_that.exclusiveMaximum,_that.minimum,_that.exclusiveMinimum,_that.readOnly,_that.writeOnly,_that.externalDocs,_that.discriminator,_that.allOf,_that.oneOf,_that.anyOf,_that.not,_that.nullable,_that.allowEmptyValue,_that.collectionFormat,_that.maxLength,_that.minLength,_that.maxItems,_that.minItems,_that.pattern,_that.uniqueItems,_that.maxProperties,_that.minProperties,_that.multipleOf,_that.$deprecated,_that.extensions);case _:
  throw StateError('Unexpected subclass');

}
}