fetchTrendingGif method

Future<void> fetchTrendingGif({
  1. required String apikey,
  2. required int offset,
  3. required bool isFirstFetch,
  4. required String language,
})

Fetches a trending gif from the Giphy API.

It takes the apikey, offset, isFirstFetch, and language as parameters. It emits a GiphyLoading state if it is the first fetch. It emits a GiphySuccess state if the fetch is successful, or a GiphyError state if an error occurs.

Implementation

Future<void> fetchTrendingGif(
    {required String apikey,
    required int offset,
    required bool isFirstFetch,
    required String language}) async {
  try {
    if (isFirstFetch) {
      emit(GiphyLoading());
    }
    final response = await gifRepository.fetchTrendingGif(
        apikey: apikey, offset: offset, language: language);
    response.fold(
      (l) => emit(GiphyError(error: l)),
      (r) => emit(GiphySuccess(gif: r)),
    );
  } catch (e) {
    emit(GiphyError(error: e.toString()));
  }
}