 Hello guys in this video we are going to discuss about block so I will discuss most of the concepts related to block so this would be a theory session. Let's talk about first of all block. So block is basically a core basic library of Dart or you can say it is a Dart package that helps in implementing the block pattern. So this package is also available on Publab so you can cross check it currently its version is 8.1.2. Let's move next. Now the next is what is block pattern that we implement with the help of block package. So the block pattern is just a state management pattern. So if you haven't seen my previous video regarding state management where I have covered about different type of states such as a formal state and global state so I recommend you to watch that video as well in order to get basic idea about how the state management things work. So the block pattern is basically a state management pattern that allows your application to manage the state based on the event and make a complex application robust and testable. So if we talk about this block core package of Dart so this gonna work with different other libraries such as Flutter block, Angular block, block concurrency, block test, hydrated block, replay block. So out of which we gonna focus on Flutter block. Now the question comes what is Flutter block? So it is also a Flutter package which provide us the powerful widgets which we can use in order to implement the block pattern. So that gonna create your app very fast, reactive and robust. So if I go the simple words Flutter underscore block is a Flutter package which provides us some widgets with the help of what we can very easily implement the block design pattern. And if you need more information you can go ahead to pubdev and find Flutter underscore block. So let's take a look on the architecture of Flutter block. So using this Flutter block library we can separate our application into three layers. So before talking about that layers just take a look on this diagram. So we have this UI block and data. So this UI is basically your presentation layer that gonna handle how the screen is rendered. That means how the user interface would be. Okay whatever design you see on your app that would be included under this layer that is UI layer or you can call it presentation layer. So on presentation layer we handle different type of events, user interaction. Okay so let's say user clicked on login button user enter username and password all these things are events. So once these events are generated these events are detected by the block. Now block is your business logic layer. So it depends on different type of repositories in order to retrieve data which is required in order to create a state. So that state gonna be sent back to presentation layer so that it can be reflected on user interface side. That something has been happened. So that is your business logic layer which is going to handle the events getting data from the repository that is your network layer or your database or something else and then give it back the state to the user interface that is presentation layer. And the third one is your data layer. So this data layer basically you can say it gonna interact with the database or any network interaction or any asynchronous data source. So here this data layer basically can have the responsibility of you can say provider or something else that gonna give you data back. Okay so this data layer can be further divided into repository and data provider. And if you talk about a repository layer this is just a wrapper around one or more data providers. Fine so which we can use in order to communicate with the block. So that is just a simple overview. Next I gonna show you the basic folder structure. So basically different developers implement the block pattern in different way. But I gonna show you the basic simple folder structure in order to implement the block pattern. So first of all you gonna have your source folder which would have four different folders. Okay so you can also consider it as layers. So UI layer is there, blocks is there, repositories is there, models is there. Okay so let's talk about UI so basically on your screen whatever you see as a page that is called your UI part. So for example login page, posts page so these can be different screens and these would be considered under UI layer. And if you talk about block so there would be a corresponding block in order to handle the events related to login. So for that we have to create a separate file let's say login underscore block in order to handle all the events from the login page. Same way we would have corresponding post underscore block for handling the events related to posts page. Next we gonna have repository so this gonna interact with any network in order to authenticate in order to fetch some data in order to do any credit operation. For example in order to do authentication part with the login screen we have login underscore repository.tart. So this gonna have the logic in order to interact with the authentication server it might be a database or it might be some API or something else. And then it gonna give the response back to the block. Same way the block gonna give the state back to UI and it would be reflected whether the username is correct or not. Then we have the fourth one that is models. So generally for each response we need to have some model so that we can handle our data fetching from the model very easily. So if you have seen my previous videos you must have seen we have created couple of models for the response of the API. So that models would be placed inside this models folder. Next we gonna discuss about some basic things so I will just giving the very short description of each. Let's start with a qubit. So qubit is just a class that can be extended to manage any type of states. So we can manage states with the help of qubit as well. We can manage the states with the help of block as well. The second thing is block. So this is also a class which relies on events in order to trigger state change. So here in block we relies on events but in case of qubit there are no events we just manage the state with the help of some methods or functions you can say. Then we have block provider. So block provider is a widget that is included in Flutter underscore block library. So it provides an existing block or qubit to the widget tree. So whenever we will implement the example then I will be using this block provider. So in simple words you can say it works as dependency injection so that the instance of block or qubit can be injected to a widget tree. Then we have multi block provider. So this is also similar to block provider but in case you want to implement multiple block providers then we can use it. So in simple words you can say the multi block provider muds multiple block provider widgets into one. So basically it is used to improve you can say readability so that we don't need to do nesting of multiple block providers. Next is block builder. So block builder is also a Flutter widget which use one block and build function. So this gonna do what this gonna just respond with respect to state change. So in simple words you can say block builder gonna handle the building process of the widget once it receives a new state. So for example for login success state it would be just going to the welcome. For login fail state it would be showing a error message kind of thing. So these kind of different things we can do. We will see in the example then we have block listener. The block listener is also a Flutter widget. So that invokes the listener on state change of the block. So in case of block builder it builds a new widget once a new state is received but in case of block listener it notify that the state has been changed and accordingly you can take some decision whether to hide something rather to show something. But in case of builder it gonna build the new widget based on the state. Then we have multi block listener. So this is again the merging of multiple block listener widgets into one in order to improve reliability and eliminate the need of nesting. So these are the most commonly used topics you will encounter while working with the block. And apart from that there are two more that is repository provider. So this repository provider is also a widget that is used for dependency injection. So it basically provides a repository to a widget tree. Fine. So in block provider we use to inject one blocker qubit to the widget tree. In case of repository provider it injects the repository to a widget tree. And one more is there multi repository provider. So this is also merging of multiple repository provider widgets into one in order to improve credibility and eliminate the need of multiple repository provider nesting. Next there is a very important thing you should know about. So what is the difference between qubit and block. This is the most frequently asked question whenever interviewer discuss about block. So first of all qubit works with states but if you talk about block it is a super set of qubit that provide you the feature of qubit as well as some extra things. So here in qubit we don't have any events. We just manage everything with the help of methods or you can say functions. But in case of block you have to work with states as well as events. So qubit is very simple and less complex as compared to block. But if you talk about block that is more powerful than qubit. That is why most of the time block is recommended instead of qubit. Then if you talk about qubit everything is managed with methods instead of events. But in case of block you must have to define the events in order to reflect state change. If you're not specifying the events you cannot manage the state change. And last but not least in case of qubit there is very less spoiler plate code. But in case of block we have more boilerplate. So that is all about this qubit and block basic understanding. So in the next video we are going to discuss about implementation of this flutter underscore block package. So if you have any doubt do comment in the comment section. Otherwise look forward for next video. Thank you.