Bloc: Question about run blocs in sequence

Created on 16 Jul 2019  路  4Comments  路  Source: felangel/bloc

I have an app with an AuthBloc(the only functionality of the Bloc is authenticate the user), but i need to run other bloc(a bloc which verify my app version) before that the AuthBloc run.

I'm starting to use bloc and i don't know how i can do it, i've considerate to use the other bloc before the AuthBloc but i need the AuthBloc globally and i don't know how run the blocs in sequence before of the MaterialApp.

Do you know or do you have any example that how i can do it?

Sorry for my english.

question

Most helpful comment

Thanks for your help @felangel

All 4 comments

Hi @daviidmorales 馃憢
Thanks for opening an issue!

Regarding your question, why do you need a bloc to verify the app version? Can't you just have a service to do the verification? If so, then you can inject the service into your AuthBloc and call the verify function before authenticating the user.

Let me know if that helps 馃憤

@felangel Thanks for answer me, I need to verify the app version with a version in my backend to restrict the app if it have a lower version, I would like that the verification would be in other bloc.

I'm going to integrate the service to the AuthBloc but I really want to know what do you advise me?

Can you provide a bit more information about why you think the app verification needs to be its own bloc? If you have a pure dart VerificationService you can inject the service into the AuthBloc and do something like:

mapEventToState(event) async* {
  if (event is Authenticate) {
    try {
      bool isValid = await _verificationService.verify();
      if (!isValid) {
        yield AuthenticationFailure();
        return;
      }
      await authenticate();
      yield Authenticated();
    } catch (_) {
      yield AuthenticationFailure();
    }
  }
}

Let me know if that helps 馃憤

Closing for now but feel free to comment with additional questions/details and I'm happy to continue the conversation. Alternatively, feel free to join gitter to chat.

Thanks for your help @felangel

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krusek picture krusek  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

craiglabenz picture craiglabenz  路  3Comments

rsnider19 picture rsnider19  路  3Comments

komapeb picture komapeb  路  3Comments