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

shawnchan2014 picture shawnchan2014  路  3Comments

Reidond picture Reidond  路  3Comments

frankrod picture frankrod  路  3Comments

nhwilly picture nhwilly  路  3Comments

ricktotec picture ricktotec  路  3Comments