network<T> method
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
Usage: Future<List
Implementation
Future<T?> network<T>(
{required Function(Dio api) request,
Function(Response response)? handleSuccess,
Function(DioError error)? handleFailure}) async {
try {
Response response = await request(_api);
return handleResponse<T>(response, handleSuccess: handleSuccess);
} on DioError catch (dioError) {
if (getEnv('APP_DEBUG') == true) {
NyLogger.error(dioError.toString());
}
onError(dioError);
if (_context != null) {
displayError(dioError, _context!);
}
if (handleFailure != null) {
return handleFailure(dioError);
}
return null;
} on Exception catch (e) {
if (getEnv('APP_DEBUG') == true) {
NyLogger.error(e.toString());
}
return null;
}
}