NyApiService class
- Inheritance
-
- Object
- DioApiService
- NyApiService
Constructors
-
NyApiService(BuildContext? context, {Map<
Type, dynamic> ? decoders = const {}, BaseOptions baseOptions(BaseOptions baseOptions)?, Dio initDio(Dio api)?})
Properties
- baseOptions ↔ BaseOptions?
-
Base options for the request
getter/setter pairinherited
- baseUrl → String
-
Base URL for the request
finalinherited
-
decoders
→ Map<
Type, dynamic> ? -
Map decoders to modelDecoders
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
interceptors
→ Map<
Type, Interceptor> -
Default interceptors
no setteroverride
- retry ↔ int
-
how many times should the request retry
getter/setter pairinherited
- retryDelay ↔ Duration
-
how long should the request wait before retrying
getter/setter pairinherited
- retryIf ↔ bool Function(DioException dioException)?
-
should the request retry if the retryIf callback returns true
getter/setter pairinherited
- 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 pairinherited
- useHttpOnResponse → bool
-
Use HTTP on response
finalinherited
- useInterceptors → bool
-
Use interceptors
no setterinherited
Methods
-
delete<
T> (String url, {Object? data, Options? options, CancelToken? cancelToken}) → Future< T?> - Make a DELETE request
-
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.
override
-
error(
DioException dioException) → dynamic -
Handle the
DioException
response if there is an issue.inherited -
get<
T> (String url, {Object? data, Map< String, String> ? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) → Future<T?> - Make a GET request
-
getContext(
) → BuildContext? -
Get the build context
inherited
-
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.inherited -
init(
) → void -
Initialize class
inherited
-
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 failureinherited -
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 requestinherited -
onSuccess(
dynamic onSuccess(Response response, dynamic data)) → dynamic -
Set the
onSuccess
callback for the requestinherited -
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.inherited -
post<
T> (String url, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) → Future< T?> - Make a POST request
-
put<
T> (String url, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) → Future< T?> - Make a PUT request
-
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.inherited -
setAuthHeaders(
RequestHeaders headers) → Future< RequestHeaders> -
Set the auth headers for the request.
The
headers
parameter contains the current headers.inherited -
setBaseUrl(
String baseUrl) → dynamic -
Set a
baseUrl
for the request.inherited -
setBearerToken(
String bearerToken) → dynamic -
Set a bearer token
headers
to the baseOptions variable.inherited -
setCache(
Duration? duration, String cacheKey) → dynamic -
Set the cache for the request.
inherited
-
setConnectTimeout(
Duration duration) → dynamic -
Set the
connectTimeout
for the request.inherited -
setContentType(
String contentType) → dynamic -
Set the
contentType
for the request.inherited -
setContext(
BuildContext context) → dynamic -
Set the build context (optional)
inherited
-
setHeaders(
Map< String, dynamic> headers) → dynamic -
Set new
headers
to the baseOptions variable.inherited -
setMethod(
String method) → dynamic -
Set the
method
for the request.inherited -
setOptions(
BaseOptions baseOptions) → dynamic -
Set the
baseOptions
for the request.inherited -
setPagination(
int page, {String? paramPage, String? paramPerPage, String? perPage}) → dynamic -
Apply a pagination query to the HTTP request
inherited
-
setReceiveTimeout(
Duration duration) → dynamic -
Set the
receiveTimeout
for the request.inherited -
setRetry(
int retry) → dynamic -
Set how many times the request should
retry
if it fails.inherited -
setRetryDelay(
Duration retryDelay) → dynamic -
Set the Duration how long the request should wait before retrying.
inherited
-
setRetryIf(
bool retryIf(DioException dioException)) → dynamic -
Set if the request should
shouldRetry
if theretryIf
returns true.inherited -
setSendTimeout(
Duration duration) → dynamic -
Set the
sendTimeout
for the request.inherited -
setShouldSetAuthHeaders(
bool shouldSetAuthHeaders) → dynamic -
Set if the request should
shouldSetAuthHeaders
if the shouldRefreshToken returns true.inherited -
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.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited