networkListRequestHandler<T> function

Future<void> networkListRequestHandler<T>({
  1. required Future<BaseListResponse<T>> apiCall(),
  2. dynamic onSuccess(
    1. List<T>? data
    )?,
  3. dynamic onError(
    1. String
    )?,
})

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()}");
  }
}