hi,
i am first getting data from cache and then updating data from network. using folowing code but its not working. can anyone guide ?
```
@override
Stream
final currentState = state;
if (event is Fetch && !_hasReachedMax(currentState)) {
try {
if (currentState is PostUninitialized)
{
try {
final posts = await _fetchPosts(0, cache: true);
yield PostLoaded(posts: posts, hasReachedMax: false,type:"cache");
}
catch(error,stacktrace)
{
print("Exception occured: $error stackTrace: $stacktrace");
}
final posts1 = await _fetchPosts(0);
yield PostLoaded(posts: posts1, hasReachedMax: false,type:"network");
return;
}
if (currentState is PostLoaded)
{
final posts = await _fetchPosts((currentState.posts.length/20).toInt(),);
yield posts.isEmpty
? currentState.copyWith(hasReachedMax: true)
: PostLoaded(
posts: currentState.posts + posts,
hasReachedMax: false,type: "network"
);
}
} catch (_) {
//yield PostError();
}
}
else if(event is Refresh)
{
yield PostUninitialized();
range = "";
result= "";
status = "";
opponentId = "";
final posts = await _fetchPosts(0);
yield PostLoaded(posts: posts, hasReachedMax: false,type:"network");
return;
}
else if(event is Filter && currentState is PostLoaded)
{
yield PostUninitialized();
final posts = await _fetchPosts(0);
yield PostLoaded(posts: posts, hasReachedMax: false,type:"network");
return;
}
}
```
Hi @sohampandya00 馃憢
Thanks for opening an issue!
Bloc ignores state changes when the emitted state is equal to the current state. If your state class is extending Equatable, then even if you yield a new state instance the state might be ignored if the values are the same as those on the current state. For cases where you want multiple states with the same values to trigger state changes you should avoid extending Equatable. Hope that helps 馃憤
Most helpful comment
Hi @sohampandya00 馃憢
Thanks for opening an issue!
Bloc ignores state changes when the emitted state is equal to the current state. If your state class is extending Equatable, then even if you yield a new state instance the state might be ignored if the values are the same as those on the current state. For cases where you want multiple states with the same values to trigger state changes you should avoid extending Equatable. Hope that helps 馃憤