Integrating the repository with our business logic
In our pursuit of a well-structured and efficient Flutter app, we’re now at a critical point – integrating our repository into the UI. As you may recall from Chapter 4, we adopted the bloc pattern to manage our app’s state. We’ll now apply the power of our repository to the bloc pattern. This integration brings us one step closer to achieving a clean and maintainable architecture for our Candy Store app.
The ProductsBloc
will serve as the bridge between our UI and the repository. This bloc will manage the state related to ProductsPage
in our Candy Store app. To set this up, you’ll need to create the ProductsBloc
, which will have methods for retrieving and updating product information.
Let’s walk through the steps:
- Create the
ProductsBloc
. Start by creating a new bloc class,ProductsBloc
. This class will extend theBloc
class and manage the state for product-related data: