Build Your Own Custom Code Generator in Flutter | Flutter Code Generation

Have you ever heard of packages like Freezer, Retrofit, Riverpod Generator? They're all Code Generator built using Flutter! In this video, we are going to learn to build Code Generators like these packages by building one! This Code Generator generates constructor, fromMap, toMap, copyWith functions for a model class. All we need to do is write it once in our code (sort of like creating a template), run a command and it will generate code for all the classes we have annotated. Don't know what 'annotated' means? Watch this tutorial to know more about it.
This is my personal favourite video made on this channel till now. If you have any questions/constructive criticism about this video, let me know. I'll make sure to help you out/improve on this video.
Discord: / discord
Source Code: github.com/RivaanRanawat/code...
Helpful Resources:
More About build.yaml: github.com/dart-lang/build/bl...
Riverpod Code Generator Code: github.com/rrousselGit/riverp...
Riverpod Annotation Code: github.com/rrousselGit/riverp...
Connect With Me Here:
Twitter: / ranawatrivaan
Linkedin: / rivaan-ranawat
GitHub: github.com/rivaanranawat
Mail: namanrivaan@gmail.com
Medium: / namanrivaan
Instagram: / optimalcoding
Facebook: / rivaan.ranawat

Пікірлер: 58

  • @marufhassan634
    @marufhassan634 Жыл бұрын

    It was an amazing tutorial and this may seem redundant to most but having this on your CV can give it a huge boost and make you stand out among thousands of CVs. As Rivaan mentioned, there aren't many resources where you can learn this so it's a huge contribution to the Flutter community as well. My only issue with video is that there is an error in the model class even after running code gen which shouldn't be there and commenting a model class used in codegen is a bad practice. No one is going to remember why they did it after a few weeks. If some GDE or expert can point out the issue and the fix, it would be really helpful and Rivaan can pin it in the comment section.

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thanks Maruf! Yeah, this is an issue. If someone knows how to solve it, do comment. I'll pin it for sure! Pinning Maruf's comment as of now so that it's easier to see his comment and answer if it's known🙂

  • @marana.th4

    @marana.th4

    Жыл бұрын

    what error

  • @elshimi2008

    @elshimi2008

    8 ай бұрын

    ​@@RivaanRanawat as you only want to build a Json Generator, i think all you need to do is an Extention on Person class and add the toMap and From Map Methods in there ?

  • @dabelydadi7551
    @dabelydadi7551 Жыл бұрын

    Riivan there is no one like you in this world, all your content are pretty valuable

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thank you so much Dabely, appreciate it!

  • @dabelydadi7551

    @dabelydadi7551

    Жыл бұрын

    And it is so easy to follow you much better than anyone. My best wishes for you in 2023. Reach millions of suscribers

  • @sammyjokes9613
    @sammyjokes9613 Жыл бұрын

    Every time you drop a new content, I'm eager to watch coz I know it's going to be benefiting ❤

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thank you Sammy! Better content on the way🙂

  • @md.ismailalamkhan
    @md.ismailalamkhan Жыл бұрын

    Really great explanation good job man.

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thanks Ismail!

  • @abhayrawat8812
    @abhayrawat8812 Жыл бұрын

    Super video bro.... Thanks a lot for info !!!🤟

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Happy you found it helpful🙂

  • @siddhant4882
    @siddhant4882 Жыл бұрын

    great channel and great tut, well done.

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thanks Siddhant! Glad you like it

  • @faheemullah9121
    @faheemullah9121 Жыл бұрын

    You have a unique of teaching. I appreciate your efforts and time for us. I would request you to provide us a short video on bloc pattern in flutter. That have main key points of bloc pattern. Thanks 💌

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Sure, Bloc pattern and Bloc state management tutorials coming out soon!!

  • @prashantbhardwaj7627
    @prashantbhardwaj7627 Жыл бұрын

    Thank you God for sending Rivaan.

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thank you so much Prashant, really appreciate it🙂

  • @adil_elkhallouki
    @adil_elkhallouki Жыл бұрын

    really your channel is a treasure cave👌👌👌

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Honoured you feel that way! More to come🙂

  • @randomcsguy2065
    @randomcsguy2065 Жыл бұрын

    DAMN!!!!!!!!!!!!!!!! cannut wait to see how far rivan will go in 2023

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Haha, thank you!!

  • @uglypieceofcrap5428
    @uglypieceofcrap5428 Жыл бұрын

    starting watching this right awwayyyyyyyyy

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Let me know if it was well understood! Would love to get some feedback on this!

  • @redaantar8908
    @redaantar89086 ай бұрын

    I just discovered your channel, and I’m literally amused of the knowledge you covered in your videos, i have a question pls, do you have any idea about how the apps gen services (drag and drop) such as flutterflow works behind the scenes.

  • @raphaeljaggerd3585
    @raphaeljaggerd3585 Жыл бұрын

    Hey man. I love your vids. I know your're a busy man but if you can i'd love to see a vid on intergrating flutter with openai or gtp3

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Hey Raphael, thanks for the request. I tried to build a little something with the API. The problem is there is no official chatgpt api. The unofficial one is not working because of the constant changes in chatgpt. I've commented on that issue in their package. Once it gets resolved, I'll upload the tutorial I've planned. Till then, stay tuned for something big that's coming in early jan.

  • @raphaeljaggerd3585

    @raphaeljaggerd3585

    Жыл бұрын

    @@RivaanRanawat I'm always tuned. You're just the best.

  • @kalifasenou4820
    @kalifasenou4820 Жыл бұрын

    thanks, it's realy helpfull

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Glad it helped Kalifa!

  • @RoCr7naldo
    @RoCr7naldo Жыл бұрын

    Nice one bro ❤️🙏

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thanks man!

  • @a.alg0hary549
    @a.alg0hary549 Жыл бұрын

    this channel is amazing

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thank you, glad you like them!

  • @sarathrkrishnan6610
    @sarathrkrishnan6610 Жыл бұрын

    Superb bro

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Thank you!

  • @zendphpcolombia4902
    @zendphpcolombia49029 ай бұрын

    Nice video thanks, although india english is a battle field hahaha, anyway you have a new subscriber

  • @dimilkalathiya
    @dimilkalathiya10 ай бұрын

    Amazing video rivaan I was able to create simple generator that makes extension for class to create copyWith method without error But unfortunately it turns out that this code doesn't work with latest plugin update i wasn't able to generate any code untill I've used your pubspec.lock file to lock to your versions 😅 I really appreciate your work if you got any new info please let us know on brief or new video for it will always be treat for eyes 🎉

  • @furkanacar4025

    @furkanacar4025

    8 ай бұрын

    I solved the same problem by adding graphs: 2.2.0 to the generator's dependency system.

  • @Elite7555
    @Elite75558 ай бұрын

    Alright, now I understand why everybody hates code generation in Dart.

  • @RandalLSchwartz
    @RandalLSchwartz Жыл бұрын

    At 25 minutes, you could have used `for (final entry in visitor.fields.entries)` and then referenced entry.key and entry.value without needing to reference the original structure. Much easier to avoid an off-by-1 problem as well..

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Oh right! I keep forgetting to use the for-in loop, this makes the syntax easier to use. Thanks! Also, if it's possible, can you help us with the issue mentioned in the pinned comment by Maruf? Would be of great help. As always, appreciate you taking the time and watching the vid!

  • @lightgaming1142
    @lightgaming1142 Жыл бұрын

    How would I access the generic type of the annotation ex.: @MyAnnotation how do I get the Model classname. And how should I do imports in the generated code? Like how would I import the Model class?

  • @Aboelnasrmo
    @Aboelnasrmo8 ай бұрын

    Hi Rivan , thanks for the video , i have one question , how to use it in another app?

  • @bossphotography8821
    @bossphotography8821 Жыл бұрын

    Bro please make a home services app with backend.. Love from Bangladesh 🇧🇩

  • @amitjajoo9510
    @amitjajoo9510 Жыл бұрын

    create a series on awesome notification and local notification

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    Noted!

  • @captainbohra
    @captainbohra6 күн бұрын

    hey tell me is this an ai powered assistant for code generation??

  • @aktxyz
    @aktxyz Жыл бұрын

    at one point your command line has "flutter pub run build_runner build watch " ... not sure but I think it should be "build" or "watch" ... not both?

  • @surajbhosale6095
    @surajbhosale6095 Жыл бұрын

    Can You make the crowdfunding app in flutter

  • @surajbhosale6095

    @surajbhosale6095

    Жыл бұрын

    Without using The blockchain

  • @RivaanRanawat

    @RivaanRanawat

    Жыл бұрын

    I'll try to see if I can put this in Beginners Flutter tutorial.

  • @manasas6785
    @manasas67857 ай бұрын

    Hi, I did the same steps as you did but my code isn't generating .g files. However the build is successful. example % flutter pub run build_runner build watch --delete-conflicting-outputs Deprecated. Use `dart run` instead. Resolving dependencies... Got dependencies. Building package executable... (3.4s) Built build_runner:build_runner. [INFO] Generating build script completed, took 163ms [WARNING] Throwing away cached asset graph because the language version of some package(s) changed. This would most commonly happen when updating dependencies or changing your min sdk constraint. [INFO] Cleaning up outputs from previous builds. completed, took 2ms [INFO] Generating build script completed, took 29ms [WARNING] Invalidated precompiled build script due to missing asset graph. [INFO] Precompiling build script... completed, took 450ms [INFO] Building new asset graph completed, took 621ms [INFO] Checking for unexpected pre-existing outputs. completed, took 0ms [INFO] Generating SDK summary completed, took 2.3s [INFO] Running build completed, took 2.5s [INFO] Caching finalized dependency graph completed, took 28ms [INFO] Succeeded after 2.5s with 2 outputs (6 actions) Can you guide me i'm very new to this

  • @chibuikemmichaelokpechi7230

    @chibuikemmichaelokpechi7230

    4 ай бұрын

    I have the exact same issue

  • @gultaskeen2645

    @gultaskeen2645

    3 ай бұрын

    I got something similar to this error which I solved by downgrading the flutter sdk to 3.0.0. As build_runner works on flutter 3.0.0 or lower versions