getDioClient method

  1. @override
Dio getDioClient({
  1. Duration? receiveTimeout,
  2. Duration? sendTimeout,
  3. Duration? connectTimeout,
  4. String baseUrl = '',
  5. Map<String, dynamic>? headers,
  6. List<Interceptor>? interceptors,
  7. List<int>? trustedCertificateBytes,
  8. List<String>? allowedFingerprints,
})
override

Implementation

@override
Dio getDioClient({
  Duration? receiveTimeout,
  Duration? sendTimeout,
  Duration? connectTimeout,
  String baseUrl = '',
  Map<String, dynamic>? headers,
  List<Interceptor>? interceptors,
  List<int>? trustedCertificateBytes,
  List<String>? allowedFingerprints,
}) {
  assert(trustedCertificateBytes == null || allowedFingerprints == null);

  final dio = Dio(
    BaseOptions(
      receiveTimeout: receiveTimeout,
      sendTimeout: sendTimeout,
      connectTimeout: connectTimeout,
      baseUrl: baseUrl,
      headers: headers,
    ),
  );

  if (trustedCertificateBytes != null) {
    (dio.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () {
      final securityContext = SecurityContext();
      securityContext.setTrustedCertificatesBytes(trustedCertificateBytes);
      final httpClient = HttpClient(context: securityContext);
      return httpClient;
    };
  }

  if (allowedFingerprints != null) {
    dio.interceptors.add(AllowedSSLFingerprintInterceptor(allowedSHAFingerprints: allowedFingerprints));
  }

  if (interceptors != null) {
    dio.interceptors.addAll(interceptors);
  }

  return dio;
}