UnifiedHttpClient class
A class to provide error Handeling functionality This uses Http as default Scheme and showSnackbar is default set to True When APi call through get method of this class and internet is not available , A sncakbar will appear on the screen Call init method of this class after Materialapp is Initialized and pass parameter to configure as per your choice
Constructors
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
-
init(
{bool? usehttp, bool? showSnackbar, bool? showLogs, List< UnifiedInterceptor> ? interceptors, String? baseUrl, Map<String, dynamic> ? queryParameters, Duration? connectTimeout, Duration? receiveTimeout, Duration? sendTimeout, Map<String, Object?> ? extra, Map<String, Object?> ? headers, UnifiedResponseType? responseType, String? contentType, bool? followRedirects, int? maxRedirects, bool? persistentConnection, String? refreshTokenEndpoint, List<String> ? refreshWhitelist, Future<void> onTokenRefreshed(Map<String, dynamic> newTokens)?, Map<String, dynamic> getRefreshTokenBody()?, VoidCallback? onLogout}) → void - by default it will use http and show snackbar
-
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
-
defaultHeaders
↔ Map<
String, String> -
default headers configured via init and merged
into every request for both http and dio.
Per-call headers passed to get/post/delete/multipart
will override these defaults on a key-by-key basis.
getter/setter pair
-
getRefreshTokenBody
↔ Map<
String, dynamic> Function()? -
Optional callback to provide refresh token request body.
If not provided, the package will make a POST request to refreshTokenEndpoint
with default headers (expecting refresh token in Authorization header).
getter/setter pair
- onLogout ↔ VoidCallback?
-
Callback for handling session termination
getter/setter pair
-
onTokenRefreshed
↔ Future<
void> Function(Map<String, dynamic> newTokens)? -
Callback when tokens are refreshed.
Receives the new tokens from refresh endpoint response.
Use this to save tokens to local storage.
The package will automatically retry the original request after this callback.
getter/setter pair
- refreshTokenEndpoint ↔ String?
-
Optional endpoint for refresh token
getter/setter pair
-
refreshWhitelist
↔ List<
String> ? -
Optional list of endpoints to monitor for 401 errors
getter/setter pair
- showLogs ↔ bool
-
enable console logs
getter/setter pair
- showSnackbar ↔ bool
-
default set to True
getter/setter pair
- useHttp ↔ bool
-
default set to True
getter/setter pair
Static Methods
-
clearDefaultHeaders(
) → void - Clear all default headers that were configured via init or setters.
-
delete(
String endpoint, {int timeout = 3, Map< String, dynamic> ? queryPara, dynamic body, Map<String, String> ? headers, bool isRetry = false}) → Future<Result< String> > - Delete request
-
get(
String endpoint, {int timeout = 3, Map< String, dynamic> ? queryPara, Map<String, String> ? headers, bool isRetry = false}) → Future<Result< String> > - get request
-
handle401(
Failure failure, Future< Result< retryAction(), String endpoint) → Future<String> >Result< String> > - Handles 401 UnAuthorization errors by attempting to refresh the token or calling the logout callback.
-
mapDioResponseToResult(
Response response) → Result< String> - map Dio response into Result
-
mapHttpResponseToResult(
Response response) → Result< String> - map response into Result
-
multipart(
String endpoint, {int timeout = 3, Map< String, dynamic> ? queryPara, Map<String, String> ? headers, Map<String, Map< ? files, Map<String, dynamic> >String, String> ? fields, bool isRetry = false}) → Future<Result< String> > - Multipart request for file uploads Example:
-
patch(
String endpoint, {int timeout = 3, Map< String, dynamic> ? queryPara, dynamic body, Map<String, String> ? headers, bool isRetry = false}) → Future<Result< String> > - PATCH request
-
post(
String endpoint, {int timeout = 3, Map< String, dynamic> ? queryPara, dynamic body, Map<String, String> ? headers, bool isRetry = false}) → Future<Result< String> > - POST request
-
put(
String endpoint, {int timeout = 3, Map< String, dynamic> ? queryPara, dynamic body, Map<String, String> ? headers, bool isRetry = false}) → Future<Result< String> > - PUT request
-
removeDefaultHeader(
String key) → void - Remove a single default header key at runtime.
-
setDefaultHeader(
String key, String value) → void - Convenience helper to set a single default header key/value at runtime.
-
setDefaultHeaders(
Map< String, String> headers, {bool merge = true}) → void - Replace or merge global default headers at runtime. Useful for things like setting/changing auth tokens after login.