Bloc: Missing BloC current state

Created on 24 Mar 2020  路  2Comments  路  Source: felangel/bloc

Good morning @felangel,
I found your medium post about infinite list and it is the implementation that I was looking for.
From Dec 2018 this library probably has been changed a lot, but I'm trying to reuse your code.
There is only one thing I'm not able to find: how to access to bloc currentState.
Actually the only method that I know to get the previous bloc state is to use BlocBuilder widget and manage it, but it is on the 'graphic' part of my code.
I would like to manage current state in the bloc class as in your example:

Stream<PostState> mapEventToState(PostEvent event) async* {
  if (event is Fetch && !_hasReachedMax(currentState)) {
    try {
      if (currentState is PostUninitialized) {
        final posts = await _fetchPosts(0, 20);
        yield PostLoaded(posts: posts, hasReachedMax: false);
      }
      if (currentState is PostLoaded) {
        final posts = await _fetchPosts(currentState.posts.length, 20);
        yield posts.isEmpty
            ? currentState.copyWith(hasReachedMax: true)
            : PostLoaded(
                posts: currentState.posts + posts, hasReachedMax: false);
      }
    } catch (_) {
      yield PostError();
    }
  }
}

Can you please help me?

Thank you a lot

question

Most helpful comment

I found the solution opening the repository, that contrary to my expectations, was updated using one of the latest version of flutter_bloc library.
The solution is simply to use state property!
@felangel you are the best project maintainer I've ever seen. Sorry for messing up your issue pool, tell my if you prefer I delete it or you would like to take it.

All 2 comments

I found the solution opening the repository, that contrary to my expectations, was updated using one of the latest version of flutter_bloc library.
The solution is simply to use state property!
@felangel you are the best project maintainer I've ever seen. Sorry for messing up your issue pool, tell my if you prefer I delete it or you would like to take it.

Thanks so much @enricobenedos and I'm glad you figured it out 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abinvp picture abinvp  路  3Comments

nerder picture nerder  路  3Comments

nhwilly picture nhwilly  路  3Comments

rsnider19 picture rsnider19  路  3Comments

hivesey picture hivesey  路  3Comments