fetchData method

void fetchData(
  1. Future<ApiResponse> fetchDataFunction(
    1. Map
    ),
  2. Map args,
  3. String screenReference,
  4. dynamic fun,
)

Implementation

void fetchData(
    Future<ApiResponse> Function(Map<dynamic, dynamic>) fetchDataFunction,
    Map<dynamic, dynamic> args,
    String screenReference,
    dynamic fun
    ) async {
  emit(ApiResponseState(responseState: RequestState.loading, actionFunction: fun));
  try {
    final result = await fetchDataFunction(args);
    StandardScreenResponse standardScreenResponse =
    StandardScreenResponse.fromJson(result.data);
    bool pullToRefresh = _isPullToRefreshEnabled(standardScreenResponse);
    Map<String, StandardScreenResponse?> oldMap = standardScreenResponseCubit.state.responseMap;
    standardScreenResponseCubit.updateStandardScreenResponse(
        screenReference, standardScreenResponse,oldMap);

    emit(ApiResponseState(
      responseState: RequestState.loaded,
      isPullToRefreshEnabled: pullToRefresh,
      apiResponse: result,
      actionFunction: fun
    ));
  } catch (e) {
    emit(ApiResponseState(responseState: RequestState.error, actionFunction: fun));
  }
}