Flutter Freezed Tutorial | Get Productive Write Less Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone assalamualaikum we'll see how to  use frigid package to generate bipolarate code   and we would generate them automatically what I  mean by that is over here so we have user model   and here user model Constructor and different  kind of factory Constructor from Json method and   two Json method now as your project gets bigger  and larger so you might have to generate them   you might have to write them on your own  and which is annoying and there could be   a lot of errors but there is a nice  package which does it automatically   so that package is called a frigid now this is  the package that I'm talking about free jet I   think that's how they call it anyway so first  we'll take a look how our program works without   this package so without this package I have this  user model here and everything is handwritten over   here and so this is our main screen over here  and from here we call this user list screen   and inside this user list screen as you see  I have a model model name is a model without   frigid package actually this refers to this one  over here so if we take a look at this user model   over here so this is the user model and it's  inside this model without frigid so this is   what it refers over here model without frigid and  dart so it refers to this one and here I create   object and then we add it to this user model list  over here and we create two objects and then in   our in in our build method inside this list view  Builder we access this user model list to get it   length and then we take it first name last name  things like that and we could also do like this   all right okay so now this is when you generate  model create model manually okay but as I said   that if your project gets bigger and larger you  don't want to do that do it for every model okay   so in that case this is where it comes in handy  so definitely make sure that you have this Json   annotation plugin as well as this one and this  too actually this is for plug is I guess they   work together uh at least that was with me  so go ahead and install this for plugins   but this is the core of this okay now once  you did this one uh all you need to do go   ahead and create a new model class so in this  case actually I have over here created a folder   which is called model with frigid and then Dart  and this is the model that I'm talking about   okay so over here what you need to do first you  have to mention this frigid uh foreign directive   I think they call it frigid directive and then you  have to call your class create a class and then   we have to do this one now this is also  a class but this is mixing class but this   class gets Auto generated by our package and  how to do that I'm going to show you later   and over here you see you see we have a factory  Constructor and he said there's actually we are   going to mention our fields in the model usually  the one you do over here so they are exactly the   same over here okay now in this case I have a  default value so I mention it over here by this   default directive over here okay and then you  assign this class to it now this class is also   would be Auto generated later and at the same  time here we are mentioning that I need this   from Json method okay so the body is not  here now this would be auto-generated by   our plugin so the idea is mention your frigid  directive then create a model and the related   fields inside this if you have a default value  you have to mention this default directive and   as well as give the value and everything else  stays the same and then assign your class name   one thing though over here when you use this with  a web you have to have the dollar sign before this   class name so these two classes are not  generated yet but here we'll see that   once we run our Command over here we'll see  a new new two files actually okay now what   are those two files those two files are this  okay now once again this names they have to   same as they have to be same as this one user  model at least at the beginning uh whatever   your model name is so you have to have this  small letter then underscore so separate them   and then we say that user model dot frigid now  this is also a file that would be generated Dart   file and usermodel.g that will be another Dart  file that would be generated so how to generate   to them so to be able to generate them should come  to your terminal over here and let me do a clear   over here now here we'll run this command so this  is the command that does the magic flutter pub   run build Runner build delete conflicts output  outputs so once you run this command it will   auto generate those two files and we'll see the  error is gone okay so let's go ahead and run it so it's Auto generating over here it's doing  its job and we see that the first error is gone   now hopefully the second arrow is gone now if we  open up our folder over here and we see that these   two files are Auto generated and they may look  a little bit complex okay so it generated mixing   classes for us as well as over here like this from  Json method as you can see and two Json methods so   they all did it for ourselves automatically  so it saves you writing a lot of code   now of course over here in the list screen  just now we are using without frigid   so which refer to this one but now we want to  use this files over here which is this model   actually and now this inside this frigid  directory so I'm going to change instead   of without just with Y because the name is  with frigid okay all right so we did that and over here we need to make a little bit of  change because we are using frigid package so   as it generated files for us automatically so the  earlier we're changing the Boolean value would not   work it has to be directly inside this model so  we go go and take that model the certain object   and then we change its value the field value like  over here now this would be get called from here   but anyway you might have this you might not  have this so in this case I'm using this one   to have this switch button now  it looks like it had an error   because we have a lot of changes  so let's go ahead and restart it   and now we see that we are using frigid package  over here and everything works same as before   and now even if we go ahead and delete  this directory we are still good to go great now you restart our app and you  see everything is still same as before   nothing changed okay but with this the   good thing is that you just write this amount of  code and run the command and you are good to go   anyway so if you liked it don't forget to  subscribe and smash that like button thank you
Info
Channel: dbestech
Views: 11,074
Rating: undefined out of 5
Keywords: Flutter Freezed Package, how to use flutter freezed, flutter freezed tutorial
Id: qRC8fY7ZwFQ
Channel Id: undefined
Length: 8min 24sec (504 seconds)
Published: Fri Sep 30 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.