networkListRequestHandler<T> function
Future<void>
networkListRequestHandler<T>({
- required Future<
BaseListResponse< apiCall(),T> > - dynamic onSuccess(
- List<
T> ? data
- List<
- dynamic onError()?,
Implementation
Future<void> networkListRequestHandler<T>({
required Future<BaseListResponse<T>> Function() apiCall,
Function(List<T>? data)? onSuccess,
Function(String)? onError,
}) async {
try {
final response = await apiCall();
if (response.success == Constant.successResCheckValue) {
onSuccess?.call(response.data);
} else {
onError?.call(response.message ?? "Unknown error occurred.");
}
} on DioException catch (dioError) {
onError?.call(_getDioErrorMessage(dioError));
} catch (e) {
onError?.call("Unexpected error: ${e.toString()}");
}
}