What is BLOC in flutter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is this block in flutter that was little bit exaggerated hey did everyone hit a shear and in this video and couple of upcoming videos we're going to talk about the block pattern in flutter I know some of you might be still worried about and still are confused what this block pattern but with this video and upcoming couple of videos we're gonna nail it down absolutely what block pattern in flutter is so how we're gonna nail down the block pattern in flutter first and foremost we're gonna get started with theoretical concept and we'll understand what will and how are the block pattern white is introduced how it can be implemented and how we can create an application with that and the whole idea behind the block pattern once we are done with the theoretical part after that we're gonna move on to computer and we'll try to create a simple block application we're gonna start from absolutely scratch and once we are done with that I'm gonna walk you through how to create your very first block application now during this I will give you full proof seven steps of creating block application using these seven steps you can implement them in any application and scale up your application to whatever the scale you really want to have after understanding these seven steps into the code part we're gonna move into the UI part as well we're gonna implement a very simple solution of this block concept into an application and after crafting this application I'm pretty sure you're going to be absolutely comfortable in creating any application using block pattern I am super excited to get started so let's go ahead and start this video on the block pattern in flutter so whenever you're going to hear about the block pattern there's gonna be three things that will come around again and again the first one is the stream controller second one is the sync and the third one is the stream so keep them somewhere in the back of your mind we're going to come back on to them a little bit later now first and foremost why block pattern the simple answer for this one is everybody whenever we they create an application over the time when you add more functionality in this application if your application becomes successful then definitely we want to add tons of more functionality into that now after a little bit time you're going to notice the application becomes like a spaghetti code now spaghetti code in the concept of programming is something where application is just all over the place it just mess around and even the reading of application is a total nightmare now to avoid such situation everybody loves to they start their application if it's gonna scale up quite a lot into something known as separations now these separations of the code can be done by a variety of things variety of frameworks and application and libraries it's it's a whole lot of choices that we can make one of such choices is blog and again the whole idea is we want to separate out our logical part of application from rest of all the application it includes UI as well and of course it makes sense that the more part in which you just extract your logical component it's much more easier because through that you can control what goes into that logical file and what comes out of that logical file in the future it makes your application scalable and definitely low level of errors as well apart from this breaking out the logical part this also helps us as a team work now definitely when your application is big enough a lot of people work on the team some might be on UI is some I'd beyond the logical part if you have one separate place just one place to control all the states your application then there are very less chances that anybody can mess up with that and if anybody messes up with that definitely there are way to track him down and resolve all these errors but again now it's very important to understand some of the terminologies that are associated with this block pattern so for that we need couple of great examples now in order to understand what this block pattern is there's gonna be three things that's coming up again and again stream controller sync and stream in order to remember all of this I'm gonna say just add a couple of more words they are not actual words they are fictitious just to understand and the one is sync in stream out the easiest way to remember the sync and stream out again sync in doesn't exist stream out doesn't exist sync do stream do in order to further understand that why we need to keep everybody away from what the logic part and what's happening up we need a black box but we don't have a black box but I do have a blue one and it's more than enough for us to understand so the whole idea is what happens to our data so we're data let's just say I have this big data which goes inside this magical black box or blue power and what comes out is also a pink data where is Madeira there we go so this is the one that comes out and nobody just cares about what happened to the data inside but things get really really interesting when what you do is your ping data goes in and surprisingly your yellow data comes out and that's a little bit magical but nobody should know what happened to the ping data and how it turned up into yellow only the ones the logical part should understand it and even if you want to go further beyond that what you can do is yellow goes in and on the other side if I just look at it pink and yellow both comes so that's one of the part of why we use this logical component so that nobody knows what happened to the data they just all care about the input and output and again input sink in and output stream out now further on let's write couple of notes so that we can understand once and for all what this block is and more couple of examples so that you can understand it absolutely clearly the person promise let's go at it with a block so we have got first and foremost a simple block now block stands here simply for business logic component easy to understand the whole idea of this block is what goes in and what comes out the input part is known as sink in again the sink in is for our reference actually it just called as sink the output part is known as stream and the black box which we have been calling a blue box is actually your stream controller now one more important thing that I would like to write it down for you as a star note is always close your stream just keep it back in somewhere back in mind it's gonna be useful a little bit later very important now let's close it down with having an example of why everything needs to be boxed out now for example we do have a couple of buttons let's assume that these are rigid the first button is says bye so whenever you click on a by button in order to buy a course a lot of thing happens into the logical part some of them is things like API calls maybe a payment gateway things which are logical actually happens but nobody cares about it nobody like UI designer even customer nobody cares about it how this is going to happen all they care about is they are able to just start the course and they should get a message that yes we are able to start this code and of course this whole idea of this business component of logical things needs to be separated out from everybody time for some bonus information as well now there are two concepts whenever we are writing something known as blog pattern the first concept is I would like to name this concept a little bit later first I would like to show you what actually they are let's just say we have a user one we're gonna call this as u1 now user one simply goes up and clicks on this bi button let's just say we're gonna call this as simply by and when he simply buys this one he actually goes on to some kind of a black magical box which does the buying job and then simply just like to start the course so let's go ahead this is a start course now what is going to happen during this period let's just say a u2 comes in and he also is going to try to just look into this stream by the way whenever somebody tries to do that we call it it's trying to listen into the stream and of course if somebody is buying it this should not be allowed so this is known as something known as single user subscription head about the subscriptions not like almost kind of a YouTube subscribe button so it's known as subscription of a single user again no user should be allowed to listen into the stream or should be able to subscribe now this is going to be useful for a detailed application but just wanted to give you this brief information now another kind of similar thing happens as well the second one that we are talking about let's just say our user one actually comes up again and this time user one actually does something else he's already into the course so he goes into the discussion section let's just say this is a discussion section something happens of when he tries to just write the questions and this question goes to simply a public discussion forum we're gonna call this as simply pub okay now the user two comes up and he tries to just listen to the stream probably get a notification whenever somebody just asked a question so in this case he should be allowed to just see what's happening up now definitely we're not gonna allow him to listen to anything which is happening internally but definitely this is just a base the core concept I'm trying to explain with some other references so in this case we call this as something known as broadcasting it's pretty easy concept so in this broadcast every user can actually subscribe to this event and can get notified for that again for the code that we're going to write this is a little bit overhead but still wanted to give you these concept because they are super important now by this time I expect that you have a little bit understanding that we do have a stream controller we have something known as sync and something known as strain apart from that I just expect you have a little bit overview idea because rest of the things are gonna get clearer up when we are going to actually write this code again always remember the whole idea is to separate our state or the logical part from the rest of the code so next we are going to fire up our favorite editor which is BS code we are going to create a simple flutter project and we are going to nail it down everything into the code file as well so let's go ahead and move on to the computer screen that we're going to nail down this entire block operations and thought patterns in the flutter let's go ahead and catch up into the computer screen and again don't forget to hit that subscribe on my YouTube as well I have amazing things on my youtube channel as well so go ahead hit that subscribe they're moving into the computer screens in three two actually next video [Music]
Info
Channel: Hitesh Choudhary
Views: 63,123
Rating: undefined out of 5
Keywords: Programming, LearnCodeOnline, BLOC, Flutter, machine learning, Arificial inteligence, Dart, State management, Flutter tutorials
Id: Un7eG5hHNPg
Channel Id: undefined
Length: 10min 13sec (613 seconds)
Published: Mon May 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.