fetchData method
void
fetchData(
- Future<
ApiResponse> fetchDataFunction(), - Map args,
- String screenReference,
- 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));
}
}