Bloc: Can I Use Multiple BlocBuilder in same class

Created on 19 Sep 2019  路  2Comments  路  Source: felangel/bloc

Describe the bug
I used Flutter_bloc for authentication with firebaseAuth
. And now I used Flutter_bloc for Changing Theme at run-time
and these two blocBuilder exists in main class as shown bellow:

Code:

  @override
  Widget build(BuildContext context) {
    return BlocBuilder(
      bloc: changeThemeBloc,
      builder: (BuildContext context, ChangeThemeState state) {
        return MaterialApp(
          theme: state.themeData,
          home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
            builder: (context, state) {
              if (state is Uninitialized) {
                return SplashScreen();
              }
              if (state is Unauthenticated) {
                return LoginScreen(userRepository: _userRepository);
              }
              if (state is Authenticated) {
                return HomeBase(name: state.displayName);
              }
              return null;
            },
          ),
        );
      },
    );
  }

As shown I used bloc inside another bloc is there any problem ?
And thanks for your efforts.

question

All 2 comments

it's ok I think, since they are different streams, but be aware that when the Theme bloc changes state, it will rebuild the entire widget tree (which is the intended behavior I guess? )

Hi @gtxgat 馃憢
Thanks for opening an issue!

As @bigworld12 mentioned, it's perfectly fine to nest BlocBuilders so long as you are intending the child of each BlocBuilder to re-render on each state change 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

1AlexFix1 picture 1AlexFix1  路  3Comments

tigranhov picture tigranhov  路  3Comments

abinvp picture abinvp  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

nerder picture nerder  路  3Comments