DioApiService class
Base API Service class
- Implementers
Constructors
- DioApiService(BuildContext? context, {BaseOptions baseOptions(BaseOptions baseOptions)?, Dio initDio(Dio api)?})
Properties
- baseOptions ↔ BaseOptions?
-
Base options for the request
getter/setter pair
- baseUrl → String
-
Base URL for the request
final
-
decoders
→ Map<
Type, dynamic> ? -
Decoders for morphing json into models
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
interceptors
→ Map<
Type, Interceptor> -
Interceptors for the request
no setter
- retry ↔ int
-
how many times should the request retry
getter/setter pair
- retryDelay ↔ Duration
-
how long should the request wait before retrying
getter/setter pair
- retryIf ↔ bool Function(DioException dioException)?
-
should the request retry if the retryIf callback returns true
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shouldSetAuthHeaders ↔ bool
-
should the request retry if the retryIf callback returns true
getter/setter pair
- useHttpOnResponse → bool
-
Use HTTP on response
final
- useInterceptors → bool
-
Use interceptors
no setter
Methods
-
displayError(
DioException dioException, BuildContext context) → dynamic - Display a error to the user This method is only called if you provide the API service with a BuildContext.
-
error(
DioException dioException) → dynamic -
Handle the
DioException
response if there is an issue. -
getContext(
) → BuildContext? - Get the build context
-
handleResponse<
T> (Response response, {dynamic handleSuccess(Response response)?}) → dynamic -
Handles an API network response from
Dio
.handleSuccess
overrides the return valuehandleFailure
is called then the response status is not 200. You can return a different value using this callback. -
init(
) → void - Initialize class
-
network<
T> ({required dynamic request(Dio api), dynamic handleSuccess(Response response)?, dynamic handleFailure(DioException error)?, String? bearerToken, String? baseUrl, bool useUndefinedResponse = true, bool shouldRetry = true, bool? shouldSetAuthHeaders, int? retry, Duration? retryDelay, bool retryIf(DioException dioException)?, Duration? connectionTimeout, Duration? receiveTimeout, Duration? sendTimeout, Duration? cacheDuration, String? cacheKey, Map< String, dynamic> ? headers}) → Future<T?> -
Networking class to handle API requests
Use the
request
callback to call an APIhandleSuccess
overrides the response on a successful status codehandleFailure
overrides the response on a failure -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
dynamic onError(DioException dioException)) → dynamic -
Set the
onError
callback for the request -
onSuccess(
dynamic onSuccess(Response response, dynamic data)) → dynamic -
Set the
onSuccess
callback for the request -
onUndefinedResponse(
dynamic data, Response response, BuildContext? context) → dynamic -
Handle the undefined response's for HTTP requests.
The
data
parameter contains what was returned from your decoder. -
refreshToken(
Dio dio) → dynamic -
Perform a
Dio
request to update the users auth token. This method is called when shouldRefreshToken returns true. You can override this method to perform your own request. Thedio
parameter is a new instance ofDio
. You can use this to perform a request without affecting the originalDio
instance. -
setAuthHeaders(
RequestHeaders headers) → Future< RequestHeaders> -
Set the auth headers for the request.
The
headers
parameter contains the current headers. -
setBaseUrl(
String baseUrl) → dynamic -
Set a
baseUrl
for the request. -
setBearerToken(
String bearerToken) → dynamic -
Set a bearer token
headers
to the baseOptions variable. -
setCache(
Duration? duration, String cacheKey) → dynamic - Set the cache for the request.
-
setConnectTimeout(
Duration duration) → dynamic -
Set the
connectTimeout
for the request. -
setContentType(
String contentType) → dynamic -
Set the
contentType
for the request. -
setContext(
BuildContext context) → dynamic - Set the build context (optional)
-
setHeaders(
Map< String, dynamic> headers) → dynamic -
Set new
headers
to the baseOptions variable. -
setMethod(
String method) → dynamic -
Set the
method
for the request. -
setOptions(
BaseOptions baseOptions) → dynamic -
Set the
baseOptions
for the request. -
setPagination(
int page, {String? paramPage, String? paramPerPage, String? perPage}) → dynamic - Apply a pagination query to the HTTP request
-
setReceiveTimeout(
Duration duration) → dynamic -
Set the
receiveTimeout
for the request. -
setRetry(
int retry) → dynamic -
Set how many times the request should
retry
if it fails. -
setRetryDelay(
Duration retryDelay) → dynamic - Set the Duration how long the request should wait before retrying.
-
setRetryIf(
bool retryIf(DioException dioException)) → dynamic -
Set if the request should
shouldRetry
if theretryIf
returns true. -
setSendTimeout(
Duration duration) → dynamic -
Set the
sendTimeout
for the request. -
setShouldSetAuthHeaders(
bool shouldSetAuthHeaders) → dynamic -
Set if the request should
shouldSetAuthHeaders
if the shouldRefreshToken returns true. -
shouldRefreshToken(
) → Future< bool> - Check if the users auth token should be refreshed. This method is called before every request. You can override this method to perform your own checks.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited