Bloc: [Bug Or Misunderstanding] Missing parameter bloc in Login Example

Created on 28 Sep 2019  路  6Comments  路  Source: felangel/bloc

Describe the bug
When I read the example code on Bloc Login tutorial here : I found in the Putting it all together Chapter, when you initialize MaterialApp like this

class App extends StatelessWidget {
  final UserRepository userRepository;

  App({Key key, @required this.userRepository}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
        builder: (context, state) {
          if (state is AuthenticationUninitialized) {
            return SplashPage();
          }
          if (state is AuthenticationAuthenticated) {
            return HomePage();
          }
          if (state is AuthenticationUnauthenticated) {
            return LoginPage(userRepository: userRepository);
          }
          if (state is AuthenticationLoading) {
            return LoadingIndicator();
          }
        },
      ),
    );
  }
}

And under the BlocBuilder, you didn't specify the bloc to use like

BlocBuilder<AuthenticationBloc, AuthenticationState>(
        bloc: _authenticationBloc,
        builder:  Something()
      )

EDIT :I just saw #479 and it didn't understand why we can ignore bloc. Cuz my local syntax checker wouldn't pass if I don't give it a parameter.

bug documentation

Most helpful comment

Hi @imaffe thanks for pointing that out! It has been fixed in b0490bf

Thanks Felix ~

All 6 comments

There would be also a follow up quesion about The argument type 'AuthenticationBloc' can't be assigned to the parameter type 'Bloc<AuthenticationBloc, AuthenticationState>' But I will create another issue for this to let others see it.

you're using an outdated version -- v 0.20.0 introduced automatic bloc lookup. documentation always references the latest version so you should probably update.

you're using an outdated version -- v 0.20.0 introduced automatic bloc lookup. documentation always references the latest version so you should probably update.

Thanks so much for this, closing the issue.

Also I found another place didn't use this autodiscovery :
Under the same page, in Login Form chapter.

BlocBuilder<LoginBloc, LoginState>(
        bloc: _loginBloc,
        builder: (
          BuildContext context,
          LoginState state,
        ) {
          return Form(
            child: Column(
              children: [
                TextFormField(
                  decoration: InputDecoration(labelText: 'username'),
                  controller: _usernameController,
                ),
                TextFormField(
                  decoration: InputDecoration(labelText: 'password'),
                  controller: _passwordController,
                  obscureText: true,
                ),
                RaisedButton(
                  onPressed:
                      state is! LoginLoading ? _onLoginButtonPressed : null,
                  child: Text('Login'),
                ),
                Container(
                  child: state is LoginLoading
                      ? CircularProgressIndicator()
                      : null,
                ),
              ],
            ),
          );
        },


It can probably be updated to the newest version, as they are likely using inconsistent version.

Hi @imaffe thanks for pointing that out! It has been fixed in https://github.com/felangel/bloc/commit/b0490bfdfc62fa83f298fefcd12d0d02f6c61963

Hi @imaffe thanks for pointing that out! It has been fixed in b0490bf

Thanks Felix ~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hivesey picture hivesey  路  3Comments

krusek picture krusek  路  3Comments

Reidond picture Reidond  路  3Comments

RobPFarley picture RobPFarley  路  3Comments

rsnider19 picture rsnider19  路  3Comments