searchGif method

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

Searches for a gif in the Giphy API.

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

Implementation

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