init method

void init({
  1. bool useLogger = true,
  2. String? baseUrl,
  3. Interceptor? loggingInterceptor,
  4. String? authToken,
  5. int? timeout,
  6. TimeUnit? timeUnit,
})

Initializes the Dio instance and configuration settings.

  • useLogger: A boolean to enable logging of requests and responses (default: true).
  • baseUrl: A base URL for all API requests (default: null).
  • loggingInterceptor: A custom logging interceptor for logging requests and responses (default: null).
  • authToken: A global authorization token for all requests (default: null).
  • timeout: Timeout for API requests in seconds (default: null).
  • timeUnit: Time unit for timeout (default: TimeUnit.SECONDS).

Implementation

void init({
  bool useLogger = true,
  String? baseUrl,
  Interceptor? loggingInterceptor,
  String? authToken,
  int? timeout,
  TimeUnit? timeUnit,
}) {
  _baseUrl = baseUrl ?? _baseUrl;
  _timeout = timeout ?? _timeout;
  _timeUnit = timeUnit ?? _timeUnit;

  // Add logger interceptor if logging is enabled or custom logging interceptor is provided.
  if (useLogger || loggingInterceptor != null) {
    _dio.interceptors.add(loggingInterceptor ??
        PrettyDioLogger(
          requestBody: true,
          requestHeader: true,
          responseBody: true,
          responseHeader: false,
        ));
  }

  // Set the authentication token if provided.
  if (authToken != null) {
    _authToken = authToken;
  }
  _configInit = _ImpakRetroConfig(_dio); // Initialize the configuration.
}