BlocConsumer

Learn about BlocConsumer and how it's used by widgets to listen to state changes.

We'll cover the following

Now that we’ve learned about BlocBuilder and BlocListener, let's explore the scenario where we may want to use both of these widgets at the same time.

The BlocBuilder re-renders the widget returned from its builder() function whenever the state changes. On the other hand, BlocListener calls its listener() function every time the state changes. So, what if we need to re-render the widget and call a function?

We can nest both the BlocBuilder and BlocListener widgets as follows:

Get hands-on with 1200+ tech skills courses.