create static method

Dio create({
  1. required String baseUrl,
  2. Duration? timeout,
  3. required LikeRequestRegistry registry,
  4. LikeSessionScope currentSession()?,
  5. LikeAuthConfig? authConfig,
  6. List<Interceptor> customInterceptors = const [],
  7. Map<String, String> extraHeaders = const {},
  8. bool? verifySSL,
  9. String? sslCertSha256,
})

Implementation

static Dio create({
  required String baseUrl,
  Duration? timeout,
  required LikeRequestRegistry registry,
  LikeSessionScope Function()? currentSession,

  /// Optional authentication configuration scoped to this Dio stack.
  LikeAuthConfig? authConfig,

  /// Custom Dio interceptors injected **after** the built-in Like stack.
  ///
  /// Sourced from [LikeConfig.interceptors] (global) or
  /// [LikeClientConfig.interceptors] (scoped client).
  List<Interceptor> customInterceptors = const [],

  /// Extra HTTP headers merged on top of the package-level defaults.
  ///
  /// Sourced from [LikeClientConfig.defaultHeaders] for scoped clients.
  Map<String, String> extraHeaders = const {},

  /// Explicit SSL verification override. Defaults to [LikeConstants.verifySSL].
  bool? verifySSL,

  /// Explicit SSL certificate SHA-256 pin override. Defaults to [LikeConstants.sslCertSha256].
  String? sslCertSha256,
}) {
  final effectiveBaseUrl = LikeHelpers.normalizeBaseUrl(baseUrl);

  final dio = Dio(
    BaseOptions(
      baseUrl: effectiveBaseUrl,
      connectTimeout:
          timeout ?? Duration(seconds: LikeConstants.connectTimeout),
      receiveTimeout:
          timeout ?? Duration(seconds: LikeConstants.receiveTimeout),
      sendTimeout: kIsWeb
          ? null
          : (timeout ?? Duration(seconds: LikeConstants.sendTimeout)),
      headers: {'Accept': LikeConstants.defaultAcceptHeader, ...extraHeaders},
    ),
  );

  _setupInterceptors(
    dio,
    registry,
    customInterceptors,
    authConfig: authConfig,
    currentSession: currentSession,
  );

  // Delegate to the platform-correct SSL implementation:
  //   • Mobile/Desktop → like_ssl_io.dart  (IOHttpClientAdapter)
  //   • Web            → like_ssl_stub.dart (no-op)
  ssl.setupSSL(
    dio,
    verifySSL: verifySSL ?? LikeConstants.verifySSL,
    sslCertSha256: sslCertSha256 ?? LikeConstants.sslCertSha256,
  );

  return dio;
}