DioClient class

A class to manage network requests using Dio.

The DioClient class wraps a Dio instance, providing methods for making HTTP requests such as GET, POST, PUT, and DELETE. It also configures Dio with a base URL, timeouts, headers, and interceptors for logging requests and responses.

This client reads the base URL from environment variables or a local config.json file to set the base URL dynamically depending on the current environment.

Key Features

  • Base URL loaded from .env or config.json
  • Interceptors for logging requests, responses, and errors
  • Support for making GET, POST, PUT, and DELETE requests
  • Custom timeout settings for requests

Example Usage:

final dio = Dio();
final dioClient = DioClient(dio);

final response = await dioClient.get('/example-endpoint');
print(response.data);

Constructors

DioClient(Dio _dio)
Constructor to initialize the DioClient with a Dio instance.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

delete(String uri, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken}) Future<Response>
Makes a DELETE request to the specified uri.
get(String uri, {Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) Future
Makes a GET request to the specified uri.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
post(String uri, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response>
Makes a POST request to the specified uri.
put(String uri, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response>
Makes a PUT request to the specified uri.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited