network<T> method
Future<T?>
network<T>({
- required dynamic request(
- Dio api
- dynamic handleSuccess(
- NyResponse<
T> response
- NyResponse<
- dynamic handleFailure(
- NyResponse<
T> response
- NyResponse<
- 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,
- CachePolicy? cachePolicy,
- bool? checkConnectivity,
- Map<
String, dynamic> ? headers,
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<NyResponse<List
Implementation
Future<T?> network<T>({
required Function(Dio api) request,
Function(NyResponse<T> response)? handleSuccess,
Function(NyResponse<T> response)? handleFailure,
String? bearerToken,
String? baseUrl,
bool useUndefinedResponse = true,
bool shouldRetry = true,
bool? shouldSetAuthHeaders,
int? retry,
Duration? retryDelay,
bool Function(DioException dioException)? retryIf,
Duration? connectionTimeout,
Duration? receiveTimeout,
Duration? sendTimeout,
Duration? cacheDuration,
String? cacheKey,
CachePolicy? cachePolicy,
bool? checkConnectivity,
Map<String, dynamic>? headers,
}) async {
NyResponse<T> response = await networkResponse<T>(
request: request,
handleSuccess: handleSuccess,
handleFailure: handleFailure,
bearerToken: bearerToken,
baseUrl: baseUrl,
useUndefinedResponse: useUndefinedResponse,
shouldRetry: shouldRetry,
shouldSetAuthHeaders: shouldSetAuthHeaders,
retry: retry,
retryDelay: retryDelay,
retryIf: retryIf,
connectionTimeout: connectionTimeout,
receiveTimeout: receiveTimeout,
sendTimeout: sendTimeout,
cacheDuration: cacheDuration,
cacheKey: cacheKey,
cachePolicy: cachePolicy,
checkConnectivity: checkConnectivity,
headers: headers,
);
return response.data;
}