Bloc: Back navigation inside flow pages and providers for flow pages

Created on 9 Jul 2020  路  8Comments  路  Source: felangel/bloc

Hi @felangel,

I have these pages in my architecture:

  1. Init
    This page is splash screen.
  2. Intro
    This page is introduce page.
  3. Auth
    This page is authentication page.
    This page is flow of registration page and verification page.
  4. Home
    This page is home page.

In all pages, I need InitBloc, it is a general bloc I use in main.dart to route the user to the specific page according to the current situation of user (stored in db) even user reopen the app:

  • UserIsNotExist, go to Init Page.
  • UserIsRegistering, go to Auth Page.
  • UserVerified, go to Home Page.
  • ...

The Auth flow consist of two registration and verification pages.
In the registration page I need RegisterBloc and in the verification page I need both RegisterBloc and VerifyBloc blocs.

In The Home page, I need only HomeBloc and also optional InitBloc.

Now this is sample_auth for that, but I have two issues with that:

  1. I would like in the verification page, User can back to the registration page with back button of phone. But when I pressed the back button, Intro pages shown. (It seems Registration page is not pushed on the stack)

  2. In the Verification page, when I navigate to the Home page, it's not work and show the Registration page instead, beacuse I used onGenerateRoute approach you mentioned here and main route is ignored.

Thanks a lot as all your codes and your active community.

question

Most helpful comment

Finally I fixed it.
Thanks.

All 8 comments

Hi, @omidraha

could you provide your a minimal reproducible code sample how are you using it and describe desired result?

Hi,
I said on the above post.

This sample_auth is for minimal reproducible code.

And my problems are:

  1. I would like in the verification page, User can back to the registration page with back button of phone. But when I pressed the back button, Intro pages shown. (It seems Registration page is not pushed on the stack)

  2. In the Verification page, when I navigate to the Home page, it's not work and show the Registration page instead, beacuse I used onGenerateRoute approach you mentioned here and main route is ignored.

Hi, @omidraha

Sorry, I didn鈥檛 see it before, I cloned the project later to check it out.

Hi, @omidraha

Use Navigator.of(context, rootNavigator: true) can solve the problem, this problem has nothing to do with bloc.

@felangel close the issue, plz

Hi,
I tired now, and you right this Navigator.of(context, rootNavigator: true) fixed the 2 problem,
But how about first one:

  1. I would like in the verification page, User can back to the registration page with back button of phone. But when I pressed the back button, Intro pages shown. (It seems Registration page is not pushed on the stack)

Hi, @omidraha

Use WillPopScope to control the route can fix.

Since I use mac to run, I am sorry to ignore the back button.

Hi,
I tried it, but because of both registration and verification pages are in one nested navigation, and because I used onGenerateRoute approach you mentioned here to have two bloc on this auth flow, It seems both registeration and verification pages are in the stack as one route name, and I can't separate them on onWillPop method.

Finally I fixed it.
Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nerder picture nerder  路  3Comments

abinvp picture abinvp  路  3Comments

frankrod picture frankrod  路  3Comments

clicksocial picture clicksocial  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments