when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- bool showErrorMsg,
- String loadingText,
- String? contentType,
- Map<
String, dynamic> headers, - bool showDefaultLoading,
- dynamic data,
- ResponseType? responseType,
- bool? nullParams,
- RequestEncoder? requestEncoder,
- DioStart? dioStart,
- bool? returnIsString,
- String? fullUrl,
- InterceptorCall? interceptorCall,
- UrlParseFormat? urlParseFormat,
- ResponseResultCallback? responseResultCallback,
- Map<
String, dynamic> ? extra, - CancelToken? cancelToken,
- ProgressCallback? onSendCallback,
- ProgressCallback? onReceiveProgress,
- String? downloadUrl,
- 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);
}
}