Flutter Code Generation with Freezed - Data Classes & Unions/Sealed Classes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
first is a code generation package that helps you to create data classes in that it prevents you from writing hundreds of errored front lines sometimes you want objects to remain immutable for that you need an extra copro with method if you know how to implement this in that you surely know that it takes money lines of code to achieve this and that is where frust comes in do you want to learn flutter in a better and faster way then simply join our 12-week flutter training on heyeflutter.com where you master all the flutter topics such as start your idea and State Management Firebase clean architecture databases and so on by watching our structured courses that help you for each topic to go from a newbie until an expert level in flutter to use Frist added as Dev dependency in your pubspeak.yaml file and add freestyle notation as a normal dependency also at build Runner and decentralizable as Dev dependency then get your packets under your leave folder create model folder under the models folder create product folder under the product folder create a file product module.dart first create a class and create the class with freeze down notation then specify a super class next on your Constructor use the cons Factory Constructor and point it to a class with the same name prefixed with underscore inside the Constructor specify any fields that your data class will need next Implement from Json by adding a from Json Constructor and it points to a class that doesn't exist yet on the top of your files are these two part declarations and import these packets and on your terminal execute the following command the code generated by freeze will cause your linter to import warnings all you have to do is to tell the linter to ignore the listed files and generate the files by modifying your analysis option.yaml file like access on your main.darts file import the product model inside the main create this products and let's print and let's use suggestion next let's see how to make a custom method in our first class this is useful if we ever need to add custom functionality to our data class by adding a private product Constructor we are able to write custom methods let's update our product model and let's return a product quantity times the price let's rerun the command as we have updated our product model class by adding the price on the end of that file add the price for each products and let's check our customers under the models folder create product details folder then create product detail.dart file inside the file import this package add this to part declaration and create product detail class each product has brand with the default value media and product description then add from Json Factory Constructor and let's update our product model and update the products on main.dart file and run this command so as the new change takes place on your product module file make sure you have imported the product data again make sure you have imported the product detail on your main.dot file and let's debug and see if the new changes have taken place when defining a model using frizzed the code generator will automatically generate a copy with method for us this method is used to clone an object with different values as you can see on the terminal we have cloned our phone s object foreign
Info
Channel: HeyFlutter․com
Views: 8,848
Rating: undefined out of 5
Keywords: build flutter apps fast, dart data class, dart dataclasses, dart freezed tutorial, dart sealed unions, flutter automation tutorial, flutter code gen, flutter code generation, flutter code generation tutorial, flutter codegen, flutter data class, flutter data model, flutter dataclasses, flutter equatable, flutter freezed, flutter freezed tutorial, freezed dataclass, freezed unions
Id: D20Pg5iYX8c
Channel Id: undefined
Length: 3min 43sec (223 seconds)
Published: Tue Jul 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.