whenOrNull<TResult extends Object?> method

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

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(
          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() when $default != null:
      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);
    case _:
      return null;
  }
}