Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dio.clone #2095

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dio/lib/src/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,15 @@ abstract class Dio {
/// The eventual method to submit requests. All callers for requests should
/// eventually go through this method.
Future<Response<T>> fetch<T>(RequestOptions requestOptions);

/// Creates a new [Dio] instance with:
/// - Current [options]
/// - [interceptors]
/// - [httpClientAdapter]
/// - [transformer]
Dio clone({
Interceptors? interceptors,
HttpClientAdapter? httpClientAdapter,
Transformer? transformer,
});
}
14 changes: 14 additions & 0 deletions dio/lib/src/dio_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,20 @@ abstract class DioMixin implements Dio {
}
return response;
}

@override
Dio clone({
Interceptors? interceptors,
HttpClientAdapter? httpClientAdapter,
Transformer? transformer,
}) {
final dio = Dio(options);
dio.interceptors.removeImplyContentTypeInterceptor();
dio.interceptors.addAll(interceptors ?? this.interceptors);
dio.httpClientAdapter = httpClientAdapter ?? this.httpClientAdapter;
dio.transformer = transformer ?? this.transformer;
return dio;
}
}

/// A null-check function for function parameters in Null Safety enabled code.
Expand Down