when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. bool showErrorMsg,
    2. String loadingText,
    3. String? contentType,
    4. Map<String, dynamic> headers,
    5. bool showDefaultLoading,
    6. @JsonKey.new(name: 'data', toJson: _dataToJson) dynamic data,
    7. ResponseType? responseType,
    8. bool? nullParams,
    9. @igFreezedJson RequestEncoder? requestEncoder,
    10. @igFreezedJson DioStart? dioStart,
    11. bool? returnIsString,
    12. @igFreezedJson String? fullUrl,
    13. @igFreezedJson InterceptorCall? interceptorCall,
    14. @igFreezedJson UrlParseFormat? urlParseFormat,
    15. @igFreezedJson ResponseResultCallback? responseResultCallback,
    16. Map<String, dynamic>? extra,
    17. @igFreezedJson CancelToken? cancelToken,
    18. @igFreezedJson ProgressCallback? onSendCallback,
    19. @igFreezedJson ProgressCallback? onReceiveProgress,
    20. String? downloadUrl,
    21. @igFreezedJson File? savePath,
    )
)

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(
          bool showErrorMsg,
          String loadingText,
          String? contentType,
          Map<String, dynamic> headers,
          bool showDefaultLoading,
          @JsonKey(name: 'data', toJson: _dataToJson) dynamic data,
          ResponseType? responseType,
          bool? nullParams,
          @igFreezedJson RequestEncoder? requestEncoder,
          @igFreezedJson DioStart? dioStart,
          bool? returnIsString,
          @igFreezedJson String? fullUrl,
          @igFreezedJson InterceptorCall? interceptorCall,
          @igFreezedJson UrlParseFormat? urlParseFormat,
          @igFreezedJson ResponseResultCallback? responseResultCallback,
          Map<String, dynamic>? extra,
          @igFreezedJson CancelToken? cancelToken,
          @igFreezedJson ProgressCallback? onSendCallback,
          @igFreezedJson ProgressCallback? onReceiveProgress,
          String? downloadUrl,
          @igFreezedJson File? savePath)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _RequestParams():
      return $default(
          _that.showErrorMsg,
          _that.loadingText,
          _that.contentType,
          _that.headers,
          _that.showDefaultLoading,
          _that.data,
          _that.responseType,
          _that.nullParams,
          _that.requestEncoder,
          _that.dioStart,
          _that.returnIsString,
          _that.fullUrl,
          _that.interceptorCall,
          _that.urlParseFormat,
          _that.responseResultCallback,
          _that.extra,
          _that.cancelToken,
          _that.onSendCallback,
          _that.onReceiveProgress,
          _that.downloadUrl,
          _that.savePath);
  }
}