FlintClient class

A powerful HTTP client for making requests to REST APIs with support for JSON, file uploads/downloads, progress tracking, caching, and retries.

Available extensions

Constructors

FlintClient({String? baseUrl, Map<String, String> headers = const {}, Map<String, dynamic> defaultQueryParameters = const {}, Duration timeout = const Duration(seconds: 30), ErrorHandler? onError, bool throwIfError = false, RequestDoneCallback? onDone, RequestInterceptor? requestInterceptor, ResponseInterceptor? responseInterceptor, ContextualRequestInterceptor? contextualRequestInterceptor, ContextualResponseInterceptor? contextualResponseInterceptor, RequestLifecycleHooks lifecycleHooks = const RequestLifecycleHooks(), bool ignoreHookErrors = true, HookErrorHandler? onHookError, CacheStore? cacheStore, CacheConfig? defaultCacheConfig, RetryConfig? defaultRetryConfig, List<BodySerializer>? bodySerializers, List<ResponseSerializer>? responseSerializers, ResponseParseMode defaultParseMode = ResponseParseMode.lenient, Set<String>? redactedHeaders, bool debug = false, StatusCodeConfig statusCodeConfig = const StatusCodeConfig()})

Properties

baseUrl String?
Base URL for all HTTP requests.
final
bodySerializers List<BodySerializer>
final
cacheSize Future<int>
Gets the current cache size
no setter
cacheStore CacheStore
Cache store for responses
final
contextualRequestInterceptor ContextualRequestInterceptor?
final
contextualResponseInterceptor ContextualResponseInterceptor?
final
debug bool
Enables debug logging if true.
final
defaultCacheConfig CacheConfig
Default cache configuration
final
defaultParseMode ResponseParseMode
final
defaultQueryParameters Map<String, dynamic>
final
defaultRetryConfig RetryConfig
Default retry configuration - CHANGED: No retry by default
final
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, String>
Default headers to include with every request.
final
ignoreHookErrors bool
final
lifecycleHooks RequestLifecycleHooks
final
onDone RequestDoneCallback?
final
onError ErrorHandler?
Optional error handler callback.
final
onHookError HookErrorHandler?
final
redactedHeaders Set<String>
final
requestInterceptor RequestInterceptor?
Optional interceptor called before each request is sent.
final
responseInterceptor ResponseInterceptor?
Optional interceptor called after each response is received.
final
responseSerializers List<ResponseSerializer>
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
statusCodeConfig StatusCodeConfig
final
throwIfError bool
final
timeout Duration
Timeout duration for requests.
final

Methods

cleanupExpiredCache() Future<void>
Cleans up expired cache entries
clearCache() Future<void>
Clears all cached responses
copyWith({String? baseUrl, Map<String, String>? headers, Map<String, dynamic>? defaultQueryParameters, Duration? timeout, ErrorHandler? onError, bool? throwIfError, RequestInterceptor? requestInterceptor, ResponseInterceptor? responseInterceptor, ContextualRequestInterceptor? contextualRequestInterceptor, ContextualResponseInterceptor? contextualResponseInterceptor, bool? ignoreHookErrors, HookErrorHandler? onHookError, CacheStore? cacheStore, CacheConfig? defaultCacheConfig, RequestDoneCallback? onDone, RetryConfig? defaultRetryConfig, List<BodySerializer>? bodySerializers, List<ResponseSerializer>? responseSerializers, ResponseParseMode? defaultParseMode, Set<String>? redactedHeaders, bool? debug, StatusCodeConfig? statusCodeConfig, RequestLifecycleHooks? lifecycleHooks}) FlintClient
Creates a copy of this client with optional overrides.
delete<T>(String path, {Map<String, dynamic>? queryParameters, Map<String, String>? headers, String? saveFilePath, CacheConfig? cacheConfig, StatusCodeConfig? statusConfig, RetryConfig? retryConfig, JsonParser<T>? parser, ErrorHandler? onError, RequestDoneCallback<T>? onDone, CancelToken? cancelToken, Duration? requestTimeout, ResponseParseMode? parseMode}) Future<FlintResponse<T>>
Sends a DELETE request to path with optional query parameters, headers, save file path, cache config, retry config, and custom JSON parser.
dispose() → void
downloadFile(String url, {required String savePath, ProgressCallback? onProgress, RetryConfig? retryConfig, ErrorHandler? onError, StatusCodeConfig? statusConfig}) Future<File>
Downloads a file from url and saves it to savePath while optionally reporting onProgress.
get<T>(String path, {Map<String, dynamic>? queryParameters, Map<String, String>? headers, String? saveFilePath, CacheConfig? cacheConfig, StatusCodeConfig? statusConfig, RetryConfig? retryConfig, JsonParser<T>? parser, ErrorHandler? onError, RequestDoneCallback<T>? onDone, CancelToken? cancelToken, Duration? requestTimeout, ResponseParseMode? parseMode}) Future<FlintResponse<T>>
Sends a GET request to path with optional query parameters, headers, file save path, cache configuration, retry configuration, and a custom JSON parser.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch<T>(String path, {dynamic body, Map<String, dynamic>? queryParameters, Map<String, String>? headers, String? saveFilePath, Map<String, File>? files, ProgressCallback? onSendProgress, CacheConfig? cacheConfig, RetryConfig? retryConfig, JsonParser<T>? parser, StatusCodeConfig? statusConfig, ErrorHandler? onError, RequestDoneCallback<T>? onDone, CancelToken? cancelToken, Duration? requestTimeout, ResponseParseMode? parseMode}) Future<FlintResponse<T>>
Sends a PATCH request to path (similar to PUT).
post<T>(String path, {dynamic body, Map<String, dynamic>? queryParameters, Map<String, String>? headers, String? saveFilePath, Map<String, File>? files, ProgressCallback? onSendProgress, StatusCodeConfig? statusConfig, CacheConfig? cacheConfig, RetryConfig? retryConfig, JsonParser<T>? parser, ErrorHandler? onError, RequestDoneCallback<T>? onDone, CancelToken? cancelToken, Duration? requestTimeout, ResponseParseMode? parseMode}) Future<FlintResponse<T>>
Sends a POST request to path with optional body, files, headers, query parameters, progress callback, cache config, retry config, and a custom JSON parser.
preloadCache(Map<String, FlintResponse> responses) Future<void>
Preloads responses into cache
put<T>(String path, {dynamic body, Map<String, dynamic>? queryParameters, Map<String, String>? headers, String? saveFilePath, Map<String, File>? files, ProgressCallback? onSendProgress, StatusCodeConfig? statusConfig, CacheConfig? cacheConfig, RetryConfig? retryConfig, JsonParser<T>? parser, ErrorHandler? onError, RequestDoneCallback<T>? onDone, CancelToken? cancelToken, Duration? requestTimeout, ResponseParseMode? parseMode}) Future<FlintResponse<T>>
Sends a PUT request to path (similar to POST).
removeCachedResponse(String key) Future<void>
Removes a specific cached response
request<T>(String method, String path, {RequestOptions<T>? options}) Future<FlintResponse<T>>
Generic request entrypoint with a modular RequestOptions object.
saveFile(FlintResponse response, String path) Future<File?>

Available on FlintClient, provided by the FlintClientFileSaver extension

Saves a FlintResponse containing a file or bytes to path. Returns the saved File or null if the response is not a file.
saveResponseData(FlintResponse response, String path) Future<File>

Available on FlintClient, provided by the FlintClientFileSaver extension

Saves response data to path. Supports File, List<int>, String, Map, and List.
toString() String
A string representation of this object.
inherited
uploadFile<T>(String path, {required File file, String fieldName = 'file', dynamic body, Map<String, dynamic>? queryParameters, Map<String, String>? headers, String? saveFilePath, ProgressCallback? onSendProgress, StatusCodeConfig? statusConfig, CacheConfig? cacheConfig, RetryConfig? retryConfig, JsonParser<T>? parser, ErrorHandler? onError, RequestDoneCallback<T>? onDone, CancelToken? cancelToken, Duration? requestTimeout, ResponseParseMode? parseMode}) Future<FlintResponse<T>>

Available on FlintClient, provided by the FlintClientFileSaver extension

Uploads a single file using multipart/form-data.
uploadFiles<T>(String path, {required Map<String, File> files, dynamic body, Map<String, dynamic>? queryParameters, Map<String, String>? headers, String? saveFilePath, ProgressCallback? onSendProgress, StatusCodeConfig? statusConfig, CacheConfig? cacheConfig, RetryConfig? retryConfig, JsonParser<T>? parser, ErrorHandler? onError, RequestDoneCallback<T>? onDone, CancelToken? cancelToken, Duration? requestTimeout, ResponseParseMode? parseMode}) Future<FlintResponse<T>>

Available on FlintClient, provided by the FlintClientFileSaver extension

Uploads many files in one multipart/form-data request.
withQuery(Map<String, dynamic> query) FlintClient
ws(String path, {Map<String, dynamic>? params, Map<String, String>? headers}) FlintWebSocketClient

Operators

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