NyBaseApiService class

Base API Service class

Constructors

NyBaseApiService(BuildContext? context)

Properties

baseOptions ↔ BaseOptions?
getter/setter pair
baseUrl String
final
decoders Map<Type, dynamic>
final
hashCode int
The hash code for this object.
no setterinherited
interceptors Map<Type, Interceptor>
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
useHttpOnResponse bool
final
useInterceptors bool
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.
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 value handleFailure 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, Map<String, dynamic> headers = const {}}) Future<T?>
Networking class to handle API requests Use the request callback to call an API handleSuccess overrides the response on a successful status code handleFailure overrides the response on a failure
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(DioException dioException) → dynamic
Handle the DioException response if there is an issue.
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.
setBaseUrl(String baseUrl) → dynamic
Set a baseUrl for the request.
setBearerToken(String bearerToken) → dynamic
Set a bearer token headers to the baseOptions variable.
setContext(BuildContext context) → dynamic
Set the build context (optional)
setHeaders(Map<String, dynamic> headers) → dynamic
Set new headers to the baseOptions variable.
setPagination(int page, {String? paramPage, String? paramPerPage, String? perPage}) → dynamic
Apply a pagination query to the HTTP request
toString() String
A string representation of this object.
inherited

Operators

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