Great video! As for VsCode users, Dart Data Class Generator Extension is a great choice, as you don't need any dependencies, just right click the class and press generate json data
@Gabeyre4 жыл бұрын
Thanks for mentioning Dart Data Class Generator Extension - the Github ( github.com/bnxm/Dart-Data-Class-Generator ) has nice animation showing you can create a serializable class from bare bones model and a beta json (from APi) direct to serializable model. That sounds exciting !
@mrvfino3 жыл бұрын
This saved me after 3 sleepless nights, so thanks! The package docs hasn't really made some of those parts clear, in contrast to yours that's concise and very clear to understand.
@megrel5403 Жыл бұрын
I love you man, you just saved me a headache
@RetroPortalStudio4 жыл бұрын
If you find this video useful, consider Following me on: Twitter: twitter.com/theretroportal Instagram: instagram.com/retroportalstudio LinkedIn: www.linkedin.com/in/parasjainrps Happy Coding! ✌️😁
@maha28183 жыл бұрын
Clear explanation. Awsome work. Thanks a lot.
@ahmedmohamedabdelsamie83843 жыл бұрын
deserve more than one like man.
@abhishekbhambure51463 жыл бұрын
That was a great explanation , It really cleared my all doubts and thanks for creating this awesome video , I read Flutter Complete Reference Book before watching this video , Keep going Bro
@aldyanimayazar78044 жыл бұрын
You just save my day. I wanna learn more .. thank you
@SergeKnysh4 жыл бұрын
Short and clear - thank you!
@SerreosBebis4 жыл бұрын
Precise and to the point. Thank you!
@SHAFIulBARI4 жыл бұрын
Great solution, I can't thank you enough. Be safe and keep up the good work.
@BillBrutzman3 жыл бұрын
Very helpful and appreciated. Consider adding _ demo _ actually running the code with mock data.
@anmarm.94874 жыл бұрын
Always enjoy your videos.. thumbs up
@thefamousdjx3 жыл бұрын
Can you please explain why its necessary to convert the json to a class before using it? Im not an advanced flutter user but in my apps I just use the json as it is after receiving it and then map what I need to my list views
@vibhor6912 жыл бұрын
Exactly my question, please answer this someone
@sokhavirithsorn33802 жыл бұрын
@UCVNOpQmLyxS_qlqUi9eVFRg Similar question to why we need Typescript when we can already use Javascript just fine. Easy to work in a big group since everything is clearly defined for example what fields does a User contains where you might get confused with only json especially when you need to comeback and debug your app a few months later. Avoid errors for example a field can be null or string if you use json your IDE will suggest you to handle the errors accordingly. Another thing is since everything is clearly typed your IDE will be able to give you auto suggestions which increase your development speed (Very useful in my experience if your json is very complex where I have to go and look back at the json multiple times). You might not notice the problems if you work in small group/alone or haven't maintain the app a few months later. I have maintained others people code and it is always a blessing when the developers have everything clearly typed since it gives me a great sense of what the data looks like . So in short, 1. Easier to work in group, 2. Easier to scale and maintain project in a long run, 3. Help with avoiding errors in production, 4. Auto suggestions during development.
@vibhor6912 жыл бұрын
@@sokhavirithsorn3380 thankyou for the beautiful explaination , appreciate it ❤
@prakashanuvadia88702 жыл бұрын
Thanks it's nice and easy explain. i have one question user upload image file is converted in to Json and get back to user in image this way?
@ArpitA57244 жыл бұрын
Great solution. Will be trying this on the next project.
@danielm39774 жыл бұрын
Fantastic!!!!!!👏👏
@nabil.hamawi2 жыл бұрын
can I use it for Image ?
@praneethchinna9694 Жыл бұрын
But I have one doubt how will we test the file or how to write a test case ?
@MahbuburRahman-uc7np3 жыл бұрын
My class has TImestamp field so .g.dart file is not generating. How can I solve this problem?
@ghasemDev4 жыл бұрын
Great explanation. thank you.
@abdullahibnamukta92883 жыл бұрын
How to post in database this nested json ?
@algife4 жыл бұрын
Solution starts at 3:42
@king40534 жыл бұрын
What if I'm using a model class from a pub.dev package?
@starphoto694 жыл бұрын
excellent, many tanks!
@WorstDeveloper4 жыл бұрын
I don't like all the boilerplate code for those packages either, but it's a bit better at least. I wonder why Dart needs the boilerplate, I've never had to do that in any other language.
@danarputra91814 жыл бұрын
Well boilerplate make your program easy to understand
@francisnike75454 жыл бұрын
@@danarputra9181 I doubt that
@ea88413 жыл бұрын
most pathetic language ever
@bhuvanlal72744 жыл бұрын
What is difference between factory and named constructors ??
@zekaidemir93044 жыл бұрын
How can i make php mysql database to json data?
@MMLProfessional3 жыл бұрын
I tried to apply the tutorial , but the class was not generated and I got these errors error: Target of URI hasn't been generated: 'user.g.dart'. (uri_has_not_been_generated at [yat_flutter_app] lib\user.dart:3) Generator cannot target libraries that have not been migrated to null-safety.
@ea88413 жыл бұрын
galti kardia bhai dart chose karke ye av tak null safety issue solve nai hua hai
@ea88413 жыл бұрын
sabse bakwas language hai ... java me shift hona hoga lagra
@ea88413 жыл бұрын
aur koi reply nai aane wala hai is bande ka
@Procsis12 жыл бұрын
@@ea8841 I can't understand this language, please write with English
@Procsis12 жыл бұрын
@@ea8841 I can't understand this language, please write with English
@hassanosama3574 жыл бұрын
Thanks, Do this with more briefly too.
@storylineteam4 жыл бұрын
Also i am trying to find a way around enums... right now i just pas the enum value as a string and deserialize it back using if statement... Do you have any other approach on this?
@Gabeyre4 жыл бұрын
I've never had to pass enums back and forth! Just object, nested objects, or lists of objects and by objects I mean full blown data classes (view models or whatever you wanna call it.) Can you describe a situation where one would pass enum as a parameter to an API method call?
@RetroPortalStudio4 жыл бұрын
Precisely my Question ! an Explaination would be great to solve the issue :)
@storylineteam4 жыл бұрын
@@Gabeyre I am creating a pet adoption app for a client, in the Pet model, i have an enum of type PetType that contains dog and cat, then when i retrieve the map from firestore, i use petType: map['petType'] == "PetType.Cat" ? PetType.Cat : PetType.Dog, in the frommap method constructor and "petType': petType.toString()," in the toMap contructor. I know there are lots of other approaches on this, like a PetType base class, but coming from a c# background i am used to Enums as they can help me with abstraction.
@roipeker4 жыл бұрын
@Storyline Team Games u might have to get redundant on that and rely on a Map, to actually map the strings to enums. Where to put the var? Maybe in the global space or same scope as ur enum... and use “import as “ to make it more “clear”? This is one of the main reasons i don’t use enums.often, I rather a simple good old class with private constructor, and constants that define whatever value/values i like directly using instances of the same class... more encapsulated and versatile.
@Gabeyre4 жыл бұрын
@@storylineteam You are right, I can see the constant conversion from PetType to String (to Firestore) and from String to PetType (from Firestore). This is pretty much how I would do it too if I have to use enum property in a model. And since it s Pet model (where there are many pets, cat, dog, fish, etc where you have to manage many different types) using an enum as the pet type makes a lot of sense.
@msalih3 жыл бұрын
Great!
@leosconflicts4 жыл бұрын
Nice video, but what happens when a model extends another model? Like User could extends Person, would the serialization work in same way?
@kalpafernando19984 жыл бұрын
thanks man
@marco_di2 жыл бұрын
Great Tutorial 👍🤩 ... is it also usable with Strapi v4 & GraphQL? The JSON's there are looking like very complex JSON's. ClassUser { Data { id, attributes { firstName, lastName, age ... it seems like user information is in a subclass "attributes", a subclass of the user "id"
@plugarutudor-stefan79043 жыл бұрын
explicitToJson: true --> 2h to find the solucion, THANK YOU
@ballaumer97403 жыл бұрын
its fuckin AWESOME
@Gabeyre4 жыл бұрын
I imagine this serialization will become built in to Dart core sooner or later. I use DotNetCore api and I can throw regular c# objects as IActionResult tasks and dotNetCore makes it a json, xml or whatever the httpRequest wants. In Dart/Flutter though, we gotta do this Json serialization setup for every single object. ( I mean this isn't done in javascript - well because it is java script objects - the json - but, Why should dart/Flutter devs have to always do this hand-coding serializtion? If it weren't for json-serializor library mentioned here, I would've quit Flutter before I even began using it.
@storylineteam4 жыл бұрын
as a C# dev, i hope google makes some similar improvements in dart... For example the lack of interfaces forces us to use abstract classes in cases where a simple interface can do the job etc
@LucaFang4 жыл бұрын
@@storylineteam In Dart classes declaration are interfaces themselfs. You can implement an abstract class as an interface just like you do in Java or C#. Dart just don't have "interface" as keyword. The concept is the same.
@matjazkranjc3 жыл бұрын
@AMG you should never write your own DTOs if you are communicating with another service. You should generate API which is then used. This generates the model needed and API calls as well. This video is not the best case.
@xPerfectyy4 жыл бұрын
It has limitation, if the api fields differ from your model it will be useless.
@RetroPortalStudio4 жыл бұрын
That in itself is not a good approach but yes.. if that is the case and you are getting api from some third party or something... this won't work !
@xPerfectyy4 жыл бұрын
Even if you wanted to change the fields manually, i noticed that the file generated, contain a messege indicating that we should not change it, do you have any idea why?
@funprograms26614 жыл бұрын
Am shocked!!! Is this even legal?? With just a simple cmd and boom!
@jamesperry44703 жыл бұрын
With JSON serialization, you are not converting JSON to dart classes, you are converting JSON to dart objects
@matjazkranjc3 жыл бұрын
Thank you for your effort to go into explaining thing. But! If you have existing backend with a lot of endpoints and huge model, this approach is useless. Guys and gals, better invest learning time into creating API client which do everything for you from json schemas. Flutter is a frontend and to use it as such, you should not write and maintain your own DTOs. This work was done by someone else already, programming is all about writing once and then reusing it. This approach in video is not reusing. Cheers