DioExtended class
A base class that extends Dio functionality with standardized request handling, error wrapping, and optional token-refresh logic.
This class provides generic request helpers (get, post, put, delete)
that automatically return an ApiResult — unifying success and error
responses for cleaner business logic.
It also integrates:
- Custom logging via
LogApiInterceptor - Token auto-refresh with
DioInterceptor
Example usage:
final dio = DioExtended( baseUrl: 'https://api.example.com');
final result = await dio.get<User>('users/1', decoder: User.fromJson);
if (result.isSuccess) {
print(result.data);
} else {
print(result.errorMessage);
}
Constructors
-
DioExtended({required String baseUrl, Map<
String, String> ? headers, int tokenExpiredCode = 401, Duration timeout = const Duration(minutes: 1), String? globalErrorMessage, String? globalErrorNetworkingMessage}) - Creates a new DioExtended instance with standardized configuration.
Properties
- dio → Dio
-
Exposes the underlying Dio instance for direct usage if needed.
no setter
- globalErrorMessage → String?
-
final
- globalErrorNetworkingMessage → String?
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeout → Duration
-
final
- tokenExpiredCode → int
-
final
Methods
-
callApiRequest<
T> ({required Future< Response> request(), required T parseData(dynamic data), Duration? timeout}) → Future<ApiResult< T> > - A centralized wrapper for executing API requests and returning a standardized ApiResult.
-
delete(
String endpoint, {dynamic body, dynamic query}) → Future< Response> -
Sends an HTTP DELETE request to the specified
endpoint. -
get(
String endpoint, {dynamic query}) → Future< Response> -
Sends an HTTP GET request to the specified
endpoint. -
handleTokenExpired(
) → Future - Override this in subclasses to manually handle token refresh.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
post(
String endpoint, {required dynamic body, dynamic query, dynamic customheader}) → Future< Response> -
Sends an HTTP POST request to the specified
endpoint. -
put(
String endpoint, {dynamic body, dynamic query, dynamic customheader}) → Future< Response> -
Sends an HTTP PUT request to the specified
endpoint. -
sendFormData(
String endpoint, {Map< String, List< ? files, List<File?> >File?> ? singleFiles, String singleFieldName = 'image', Map<String, dynamic> ? body, FormDataMethod method = FormDataMethod.post}) → Future<Response> - Supports:
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited