Bloc: [DISCUSSION] Deprecate BlocBuilder and BlocListener, keep only BlocConsumer, and add child param

Created on 11 Jul 2020  路  5Comments  路  Source: felangel/bloc

The birth of BlocConsumer is actually to reduce the tedious code, which is worth it.
But the birth of BlocConsumer will also confuse some people. If we just give users the concept of BlocConsumer, I think it will better understand bloc.

example:

BlocConsumer(
  // Only use child or builder
  child: someWidget,
  // builder: (context, state, child) { ... },
  listener: (context, state) { ... },
)

I think this way, bloc will be simpler and more flexible.

Want to know what feedback about this.

enhancement candidate feedback wanted flutter_bloc wontfix

Most helpful comment

  1. Builder is more idiomatic to Flutter, which has a dozen of Builder classes and only a couple of Consumers. Which seems only logical considering that every widget has a build method.
  2. AFAIU BlocConsumer was introduced to reduce the boilerplate of nesting BlocListener and BlocBuilder, which are very basic, common and easy to understand concepts. So how it is expected to facilitate understanding by removing this foundation in favor of the compound class with the more complex constructor and the mutually exclusive attributes?
  3. A shift from simpler concepts to syntactic sugar completely often does not introduce more clarity but just making it easier to write complex stuff (but not to read it). This alone is not enough to drop basic entities which it consists of.
  4. Obviously nobody expects the BlocProvider to be removed in favor of the MultiBlocProvider which was introduced for the similar design reasons.

All 5 comments

I would prefer Consumer and Listener each having one single purpose. It's clearer that way.

I don't think including a double meaning for a widget makes it simpler.

BlocConsumer can do BlocBuilder, so, why do we need BlocBuilder? Is it better to use BlocConsumer instead of BlocBuilder.

Let us think about the relationship between BlocConsumer and BlocBuilder, BlocListener,
BlocConsumer is a BlocBuilder that adds a listener, and also a BlocListener that adds a builder. BlocConsumer is like a fusion of the two, but is it different?

Perhaps it is a good choice to keep only BlocConsumer and BlocListener?

  1. Builder is more idiomatic to Flutter, which has a dozen of Builder classes and only a couple of Consumers. Which seems only logical considering that every widget has a build method.
  2. AFAIU BlocConsumer was introduced to reduce the boilerplate of nesting BlocListener and BlocBuilder, which are very basic, common and easy to understand concepts. So how it is expected to facilitate understanding by removing this foundation in favor of the compound class with the more complex constructor and the mutually exclusive attributes?
  3. A shift from simpler concepts to syntactic sugar completely often does not introduce more clarity but just making it easier to write complex stuff (but not to read it). This alone is not enough to drop basic entities which it consists of.
  4. Obviously nobody expects the BlocProvider to be removed in favor of the MultiBlocProvider which was introduced for the similar design reasons.

I completely agree with @jibiel. Closing this for now but if anyone has a strong argument in favor of removing BlocBuilder and BlocListener feel free to leave a comment and I鈥檓 happy to reopen the issue 馃憤

Was this page helpful?
0 / 5 - 0 ratings