felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.84k stars 3.4k forks source link

Pull to refresh I am getting error on pull to refresh page #1059

Closed bhavikvashi1804 closed 4 years ago

bhavikvashi1804 commented 4 years ago

https://github.com/bhavikvashi1804/flutter_BLoC_Weather_App

check this repository, I have made this by my own with the help of bloclibrary

Pull to refresh does not work, always go to an infinite loop.

bhavikvashi1804 commented 4 years ago

1st refresh work completely 2nd refresh goes to stuck

felangel commented 4 years ago

Hi @bhavikvashi1804 👋 Thanks for opening an issue!

That's because the second time you refresh the state stays the same from the bloc so no transition occurs. In order to resolve this you can either remove Equatable from your WeatherState or add a lastUpdated property to your Weather model as is done here: https://github.com/felangel/bloc/blob/b9e31f33c3082c611929729208fbcf89828954b5/examples/flutter_weather/lib/models/weather.dart#L64

That will ensure that whenever you request weather it will always be different and trigger a state change.

Hope that helps 👍