NyBaseApiService class
Base API Service class
Constructors
- NyBaseApiService.new(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
- useInterceptors → bool
-
final
Methods
-
displayError(
DioError dioError, BuildContext context) → dynamic - Display a error to the user This method is only called if you provide the API service with a BuildContext.
-
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(DioError error)?, String? bearerToken, String? baseUrl, Map< String, dynamic> headers = const {}}) → 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(
DioError dioError) → dynamic - Handle the DioError response if there is an issue.
-
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. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited