upsplash-flutter icon indicating copy to clipboard operation
upsplash-flutter copied to clipboard

Bug in fetchEvent

Open chemickypes opened this issue 4 years ago • 0 comments

Hi @xyarim I saw that in the file photo_list_bloc.dart there are two bugs!

  • Instruction CurrentPage++ passes old value and then update itself
  • Unsplash api error: page=0 gives the same result of page=1

I fixed like following:

 if (currentState is InitialPhotoListState) {
          final photos = await photoRepository.getPhotos(1);
          yield PhotoListLoaded(photos, 1);
        } else if (currentState is PhotoListLoaded) {
          int currentPage = currentState.page + 1;
          final photos = await photoRepository.getPhotos(currentPage);
          print("current_page = $currentPage");
          yield photos.isEmpty
              ? currentState.copyWith(photos)
              : PhotoListLoaded(currentState.photos + photos, currentPage);
        }

I hope you'll enjoy it!

Angelo

chemickypes avatar Apr 27 '20 17:04 chemickypes