ApiClient class abstract

An abstract class representing a client for interacting with an API.

This class provides methods for making HTTP requests, handling token refresh operations, and downloading files. It uses the Dio package for HTTP requests and includes custom interceptors for error handling and token refreshing.

The ApiClient constructor sets up the base URL for requests and adds interceptors for managing cookies and refreshing tokens.

Usage Example:

class MyApiClient extends ApiClient {
  @override
  String get baseUrl => "https://api.example.com";
}
Implementers

Constructors

ApiClient()
Creates an instance of ApiClient and initializes the Dio instance. Sets up the base URL and adds interceptors for managing cookies and refreshing tokens.

Properties

baseUrl String
The base URL for the API requests.
no setter
dio → Dio
The Dio instance used for making HTTP requests.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

downloadBytes(String url) Future<Uint8List>
Downloads the content from the specified URL as a Uint8List.
downloadFile(String url, {required String savePath, required String filename}) Future<File?>
Downloads the content from the specified URL and saves it to a file.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
uploadFile({required String filePath, String uploadUrl = "/upload-file"}) Future<File>
Uploads a file to the specified upload URL.
uploadFileFromFilePicker(PlatformFile file, {String uploadUrl = '/upload-file'}) Future<File>
Uploads a file from a PlatformFile object to the specified upload URL.
uploadFileFromImagePicker(XFile file, {String uploadUrl = '/upload-file'}) Future<File>
Uploads a file from an XFile object to the specified upload URL.
uploadFiles({required List<String> filePaths, String uploadUrl = '/multi-upload-file'}) Future<List<File>>
Uploads multiple files to the specified upload URL.
uploadFilesFromFilePicker(List<PlatformFile> files, {String uploadUrl = '/multi-upload-file'}) Future<List<File>>
Uploads multiple files from a list of PlatformFile objects to the specified upload URL.
uploadFilesFromImagePicker(List<XFile> files, {String uploadUrl = '/multi-upload-file'}) Future<List<File>>
Uploads multiple files from a list of XFile objects to the specified upload URL.

Operators

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