UHttpClient class abstract

HTTP with retries, offline/cache, upload/download progress, and automatic token refresh on expired tokens. UHttpClient.send(method: "GET", endpoint: "$base/users", onSuccess: …, onError: …, onException: …)

Constructors

UHttpClient()

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

onAuthFailed ↔ Future<void> Function()?
Runs once when the session can no longer be refreshed, e.g. go to login. UHttpClient.onAuthFailed = () async => UNavigator.offAll(LoginPage())
getter/setter pair

Static Methods

multipartFileFromFile(String fieldName, File file, {String? filename, MediaType? contentType}) → Future<MultipartFile>
A multipart file from disk, streamed (not on web). await UHttpClient.multipartFileFromFile("file", File(path))
multipartFileFromUint8List(String fieldName, Uint8List bytes, {String? filename, MediaType? contentType}) → Future<MultipartFile>
A multipart file from bytes (works on web). await UHttpClient.multipartFileFromUint8List("file", bytes, filename: "a.jpg")
removeNullEntries<T>(T? json) → T?
Copy of a JSON map/list without null values (the original is not changed).
send({required String method, required String endpoint, required dynamic onSuccess(Response), required dynamic onError(Response), required dynamic onException(String), Map<String, String>? headers, Map<String, dynamic>? queryParams, dynamic body, URequestBodyType bodyType = URequestBodyType.json, String? noNetworkMessage, String? unexpectedErrorMessage, bool offline = false, Duration? cacheDuration, int retryAmount = 3, Duration timeout = const Duration(seconds: 30), void onProgress(int percent)?, bool isRetryAfterRefresh = false}) → Future<UHttpClientResponse>
Sends a request: retries network failures 3×, refreshes an expired token once, offline/cacheDuration cache the body, onProgress reports 0-100.
upload({required String endpoint, required List<MultipartFile> files, required dynamic onSuccess(Response)?, required dynamic onError(Response)?, required VoidCallback onException, Map<String, dynamic>? fields, Map<String, String>? headers, Map<String, dynamic>? queryParams, String method = "POST", Duration timeout = const Duration(minutes: 5), void onProgress(int percent)?}) → Future<void>
Multipart upload with progress (files + fields); 5 minute timeout by default. UHttpClient.upload(endpoint: url, files: [f], onSuccess: ok, onError: err, onException: fail)