![]() The Bloc will initially have a state called TodoInitial and then when we fetch the data from the repository, we can update the state to TodoLoaded. Then the UI will trigger the event TodoFetched to the Bloc. To understand it more, let’s say we want to fetch data from some kind of service. Then the data layer will return a response and the Bloc will trigger state changes. The data access layer will be the last layer in the application, it can contain a repository class which will act as an abstract class above the data access object classes.Īs you can see in the below diagram, the UI will send events to the Bloc, which will then send the requests to the data layer. Using Bloc, we can easily seperate the application into multiple layers, first we would have the presentation layer which would contain the UI/Views/widgets, then the business logic layer (Bloc) which will take care about the state changes and will have a dependency on the data access layer. Bloc has many advantages, but one of it’s main advantage is that it enables us to easily implement seperation of concern. We have also seen the provider state management which in simple terms, is a wrapper around Inherited Widgets.Īnother statement management is Bloc which stands for Business Logic Components and it is a widely used state management in Flutter. ![]() In previous tutorials we have seen the use of setState() which will trigger the build() method and update the UI with the new state. We will show an example of using both Cubit and Bloc. In this guide, we will learn about the Bloc Design Pattern and how to use it in a Flutter application.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |