bloc/examples/flutter_firebase_login/lib/register/register_form.dart fails

Created on 30 Sep 2019  路  3Comments  路  Source: felangel/bloc

Describe the bug
After successfully registering a new user, the form is unable to access AuthenticationBloc.
bloc/examples/flutter_firebase_login/lib/register/register_form.dart

if (state.isSuccess) {
          BlocProvider.of<AuthenticationBloc>(context).dispatch(LoggedIn());
          Navigator.of(context).pop();
        }

This is because navigating to this page from the login page has result in the loss of the current context.
https://github.com/felangel/bloc/blob/master/examples/flutter_firebase_login/lib/login/create_account_button.dart

Navigator.of(context).push(
          MaterialPageRoute(builder: (context) {
            return RegisterScreen(userRepository: _userRepository);
          }),
        );

To Reproduce
Steps to reproduce the behavior:

  1. Go to Login
  2. Click on Create an Account
  3. Fill out the form and click create
  4. See error

Expected behavior
After registering user should see the home page

question

Most helpful comment

Don't mind me I found the way in your recipe. Great lib and documentation! https://felangel.github.io/bloc/#/recipesflutterblocaccess

All 3 comments

Hi @nicktran29 馃憢
Thanks for opening an issue!

Unfortunately, I was unable to reproduce the issue you're describing. There shouldn't be a problem accessing the AuthenticationBloc because it is provided above the MaterialApp making it globally accessible (even across routes).

Can you please confirm that you're running the example app without any local modifications?

Closing for now but feel free to comment with additional information and I'm happy to continue the conversation 馃憤

Hi @felangel,

Thanks for looking into this.

My issue was I provided the bloc inside MaterialApp. So I guess my question is what do I need to do in order to access a bloc provided to a widget that I'm navigating away from?

Cheers.

Don't mind me I found the way in your recipe. Great lib and documentation! https://felangel.github.io/bloc/#/recipesflutterblocaccess

Was this page helpful?
0 / 5 - 0 ratings

Related issues

1AlexFix1 picture 1AlexFix1  路  3Comments

wheel1992 picture wheel1992  路  3Comments

nerder picture nerder  路  3Comments

rsnider19 picture rsnider19  路  3Comments

timtraversy picture timtraversy  路  3Comments