Freezed ❄ - Data Class & Union in One Dart Package

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 พ.ย. 2024

ความคิดเห็น • 111

  • @ResoCoder
    @ResoCoder  4 ปีที่แล้ว +30

    This tutorial *WORKS* even with the new version *0.6*
    Just use the @freezed annotation from the *freezed_annotation* package.

    • @easazade
      @easazade 4 ปีที่แล้ว

      please mention it in the video

  • @Ch1ll3dkro3te
    @Ch1ll3dkro3te 3 ปีที่แล้ว +11

    I don't know why, but your tutorials are the only ones that make sense to me! I had absolutely no motivation to learn all that stuff until I stumbled over your videos. Coming from Web, many packages and solutions seem to solve problems I don't know from typescript. Thank you so much! Keep up the good work! Perfectly organized information! 👌

  • @afolayanademola461
    @afolayanademola461 3 ปีที่แล้ว +1

    Thank you so much @Reso Coder

  • @josephcobbinah5412
    @josephcobbinah5412 3 ปีที่แล้ว +1

    This is so concise, clear, and convenient! Thanks, Reso Coder!!!! Love it

  • @RohitSharma-cw2ii
    @RohitSharma-cw2ii 4 ปีที่แล้ว +1

    I came here after complete watching of 1 and in other half you recommend me to watch this ..now i am feeling sleepy and washed my face and again start watching ..great video matt love you

  • @rsobies
    @rsobies 3 ปีที่แล้ว +2

    in my opinion, for data class it is better to use plugin "Dart Data Class", it just generates all methods and construcors (including json conversion) that freezed does, you only put fields inside a class, hit generate option and that's it, less boiler code to write yourself compering to freezed, the generated code is much more cleaner

  • @dosenbiiir
    @dosenbiiir 2 ปีที่แล้ว

    Freezed is so beautiful

  • @arahussein3827
    @arahussein3827 4 ปีที่แล้ว

    I love the way to tell us where to use it in real application.
    great job, be continued.
    your videos is extremely useful

  • @devorrahtester5439
    @devorrahtester5439 4 ปีที่แล้ว

    ok I finally get unions and a useful way to use them and it is brilliant. TY for this tutorial!

  • @malazhariy-programming
    @malazhariy-programming 2 หลายเดือนก่อน

    Good job, Reso 💙

  • @officialismailshah
    @officialismailshah 2 ปีที่แล้ว

    best video about freeze package

  • @tenhobi
    @tenhobi 4 ปีที่แล้ว +3

    Thanks for this fast clear summary. :-)

  • @markoliverbaltazar9764
    @markoliverbaltazar9764 4 ปีที่แล้ว +9

    @Reso Coder How would you apply this in your Clean Architecture? I was trying to use the Freezed package with the Models & Entities but I couldn't find a way to extend the model to the entity.

    • @cindinishimoto9528
      @cindinishimoto9528 2 ปีที่แล้ว

      @Mark, did you get it? I'm trying to do the same thing. Please, let me know!

  • @SEOTADEO
    @SEOTADEO 2 ปีที่แล้ว

    I am convinced this is going to be useful

  • @samsurya283
    @samsurya283 4 ปีที่แล้ว

    Ur doing an awesome work bro ..........loved ur voice nd ur way of teaching...❤️..............for me this is the best flutter channel ❤️🔥🔥

  • @chetan6406
    @chetan6406 4 ปีที่แล้ว

    Without watching your video liked it.

  • @FilledStacks
    @FilledStacks 4 ปีที่แล้ว +8

    Awesome video man! One question before I decide to adopt the code generation using freezed. If I change the location of the part file will it create the folder and put all the generated code in there? I want to have the generated filed in a generation folder since that code won't be manually modified. I usually have 10-20 data classes so I want to avoid having additional 2 files for each of those in the same folder.

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +3

      Thanks Dane! I unfortunately couldn't find a way to organize all the generated classes into a single file without any hassle. It should be possible by passing a certain option to the build_runner and although it kind of works, the code doesn't compile afterwards 😅
      You can, however, use *part of* pointing to just a single file (let's say it's called "gen_classes.dart"). Then, inside "gen_classes.dart" you will use *part 'gen_classes.freezed.dart'* as usual.

    • @FilledStacks
      @FilledStacks 4 ปีที่แล้ว +2

      @@ResoCoder Thanks, that's a bit of a bummer. Your solution might work though. I'll maybe try that out in an upcoming project. Keep up the good videos!

    • @aytunch
      @aytunch 4 ปีที่แล้ว +4

      @@ResoCoder There is an option in VSCode which allows you to hide part files from the explorer in the left pane. Maybe this will help?

  • @mr.spokebeats7549
    @mr.spokebeats7549 ปีที่แล้ว

    Thank you, very useful! I have a question if sombody could answer: Is possible to declare once the shared fields between unions?

  • @ThEGeEeK
    @ThEGeEeK 3 ปีที่แล้ว

    I watched this read the doc many times , now safely I can say getting hang of it.

  • @ajinkyax
    @ajinkyax 4 ปีที่แล้ว +4

    `flutter pub run build_runner watch --delete-conflicting-outputs` from where do we know more about this cmd ?
    great video :) ty

    • @toastmalone5778
      @toastmalone5778 3 ปีที่แล้ว

      Comes from the builder_runner package. Very common for any package like freezed or json_serializer for code generation

  • @vincevarga6058
    @vincevarga6058 4 ปีที่แล้ว +2

    When you started listing the packages at the beginning of the video... man, I felt that, it's confusing sometimes with all the packages providing workarounds for the Dart language.

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +3

      It's getting better, fortunately.

  • @eduardoholzmann853
    @eduardoholzmann853 4 ปีที่แล้ว +1

    Very nice, but can we separate on domain and model? like clear architecture?

  • @arnaudduquenoy2061
    @arnaudduquenoy2061 3 ปีที่แล้ว +1

    Veryyyyyyy good but sealed union concept is still hard to get it :) i would need another in depth theoritical tutorial ☺️ .. any news if the dart team is about to offer native sealed unions ?

  • @alexandervasilenko7773
    @alexandervasilenko7773 4 ปีที่แล้ว

    Nice. Like this and i'm thinking about built_value and sealed classes now... racing between packages? :))

  • @krenoys7944
    @krenoys7944 4 ปีที่แล้ว

    I do not know if I understand correctly. Union classes are responsible for handling use cases? For example, a document in a firestore - I am creating a union class with add, update and delete methods?

  • @joelcorbalan3810
    @joelcorbalan3810 4 ปีที่แล้ว

    Excellent tutorials!

  • @mallikarjunreddy5229
    @mallikarjunreddy5229 4 ปีที่แล้ว +1

    Great tutorial bro. when am using freezed with bloc library, am unable to change the state with yield keyword. How can i do so. Please make a video on freezed with bloc if possible. Thanks alot :)

  • @findsarfaraz
    @findsarfaraz 2 ปีที่แล้ว

    You make one one the best videos.
    I m not able to join your bootcamps they are too price but once I accumulate that much money. I will join you one day.
    One question...
    Can I included fields like color or IconData in data class. If I do so I receive any error while running build command.

  • @gorudonu
    @gorudonu 4 ปีที่แล้ว +1

    looks good, but I guess I will wait for asts and data classes to land in dart :)

  • @puhgeh22
    @puhgeh22 4 ปีที่แล้ว

    In 16:25 the serialized JSON (user.json) doesn't contain the proper formatting - missing quotations. How can we obtain a proper JSON format so that if we wanted to use that result to convert it back to it's associated object, we won't be having an "Unhandled Exception: FormatException..."?

  • @TamNguyen-tj8hc
    @TamNguyen-tj8hc 3 ปีที่แล้ว

    Question, can I change the the json field in method fromJson? Like when my app want to get a phone field, but the data from json is 'userid'

  • @dennisszymanski4821
    @dennisszymanski4821 4 ปีที่แล้ว +2

    Hey Matt, another awesome tutorial ! In your tdd clean architecture course you split your entities (with fields) and models (extending from the entity and havin fromJson and toJson methods) into the domain and the data layer. How would you do this with freezed? In my understanding you have the fields and the toJson and fromJson methods in the same class.

    • @markoliverbaltazar9764
      @markoliverbaltazar9764 4 ปีที่แล้ว

      Hi Dennis, have you figured out how to use Freezed in the tdd clean architecture tutorial?

    • @dennisszymanski4821
      @dennisszymanski4821 4 ปีที่แล้ว

      @@markoliverbaltazar9764 Yes, I just combined booth in the data layer as model

  • @TheDaple
    @TheDaple 3 ปีที่แล้ว

    Good job on that, thanks a million. As I am now working on that in newer versions, I encounter the following error: it doesn't want to accept the @freezed annotation unless I use "import 'package:flutter/foundation.dart';" (While using only dart ...). Unfortunately it builds then, but doesn't run... Don't know why the example wont work ...
    Just in case you have time to answer I happily appreciate that !

  • @adamkarafyllidis9264
    @adamkarafyllidis9264 4 ปีที่แล้ว

    Nice tutorial as always and great package for missing Dart features! I am starting a project with Flutter / AngularDart and was wondering if i can use Freezed package in my shared code for AngularDart!

  • @hamidjahandideh8142
    @hamidjahandideh8142 4 ปีที่แล้ว

    please make some video about best practice in writing complex apss

  • @hernancorrea2146
    @hernancorrea2146 4 ปีที่แล้ว +1

    Thanks for this video, u help me alot. Could you make a tutorial implementing bluetooth with flutter ?

    • @gerardragbir
      @gerardragbir 4 ปีที่แล้ว

      What part of bluetooth did you want? There's flutterblue or bluetooth_serial libraries - flutterblue has a few good tutorials already and serial has pretty good documentation.

    • @hernancorrea2146
      @hernancorrea2146 4 ปีที่แล้ว

      @@gerardragbir Im trying to make a chat app with bluetooth and i tried those packages but they didn't work in my project .

  • @h3w45
    @h3w45 4 ปีที่แล้ว

    Good job man.

  • @shubhamjain3028
    @shubhamjain3028 4 ปีที่แล้ว +3

    Change @immutable to @freezed in the VS Code snippet code provided by Matt

    • @devorrahtester5439
      @devorrahtester5439 4 ปีที่แล้ว

      why?

    • @50170937z
      @50170937z 4 ปีที่แล้ว

      thank you, it worked after i change to @freezed and freezed_annotation package.

  • @ObilanCenobi
    @ObilanCenobi 3 ปีที่แล้ว

    how to run it? i created flutter app and there is no way to print for example "SomeClass() = SomeClass()" to get this error from 5:28, you are not working in flutter aplication, right?

  • @weenitmaharjan1594
    @weenitmaharjan1594 3 ปีที่แล้ว

    How to enable the parameter completion? For example. in 15:56 when you press enter in User.fromJson() the argument JSON was auto-filled. In my case, the autocomplete only completes up to User.fromJson. Event the parenthesis is not completed while pressing TAB or ENTER

  • @CarlosHernandez-dv1ib
    @CarlosHernandez-dv1ib 4 ปีที่แล้ว

    thank you a lot!!!

  • @tintin537
    @tintin537 4 ปีที่แล้ว +1

    Hi Reso Coder. i had question, Can you fully substitute built_value with freezed? Does freezed cover all the serialization and deserialization of built_value?

    • @tintin537
      @tintin537 4 ปีที่แล้ว

      And by covering all of that I mean for example I use built value with a custom deserialization because I am using it with chopper and I have an end point that Some of it’s fields types changes under some circumstances and I costumed the deserialization method. Can you do this customization with this? And can you use freezed with chopper?

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +1

      Freezed uses json_serializable, so if you can make your data work with that package, you're good. It should work with Chopper just fine.

  • @rubinbajracharya9319
    @rubinbajracharya9319 4 ปีที่แล้ว +2

    Great Tutorial. Sir how are you running the main function without running any emulator?

    • @alexandrufilipescu1301
      @alexandrufilipescu1301 3 ปีที่แล้ว +1

      Hello, have you found that out by any chance?

    • @rubinbajracharya9319
      @rubinbajracharya9319 3 ปีที่แล้ว +1

      @@alexandrufilipescu1301 Actually yes. We need to remove flutter sdk from pubspec.yaml and run as a plain dart program

    • @alexandrufilipescu1301
      @alexandrufilipescu1301 3 ปีที่แล้ว +1

      @@rubinbajracharya9319 Thank you!

  • @d34dsouI
    @d34dsouI 4 ปีที่แล้ว

    Great video as always! Thank you. Could you please make a tutorial on how to use freezed with mobx especially for consuming API/json and building the UI conditionally with sealed class which will return widgets (loading, initial, error, hasData, noData, etc). Or is it unnecessary? Better to do it with plain old dart stateless widgets based on mobx store state?

  • @khairulanas
    @khairulanas 4 ปีที่แล้ว

    fire.... 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥

  • @engineeringtechnology3113
    @engineeringtechnology3113 4 ปีที่แล้ว

    You are Awesome

  • @meshkatshadik
    @meshkatshadik 3 ปีที่แล้ว +1

    I'm facing problem it says error no 78.
    😔

  • @michaelwhite5460
    @michaelwhite5460 4 ปีที่แล้ว

    Without it gives Bad State: Unexpected Diagnostics ... expected an identifier ... any idea why this occurs

  • @sambovisal6362
    @sambovisal6362 4 ปีที่แล้ว +1

    Hello. Could you please tell me the font family that you are using in your IDE?

    • @greglee7708
      @greglee7708 3 ปีที่แล้ว

      JetBrains Mono but nearly bold (Victor Mono is similar and also good:)

  • @branimirteodorovic2297
    @branimirteodorovic2297 4 ปีที่แล้ว

    Is there a way to implement generic JsonConverter for Chopper using Freezed?

  • @halilsari8402
    @halilsari8402 4 ปีที่แล้ว

    hmm let's have a look. thanks. ;)

  • @easazade
    @easazade 4 ปีที่แล้ว

    hi mat, great videos. have you done any AR app development. if so (or not) is there a library you would recommend using for AR that works both on Android and IOS

  • @yanfranca4814
    @yanfranca4814 4 ปีที่แล้ว

    Hey, it's possible to do a video using mobx and hive together? i'm really interested how can i use both together

  • @rakakhairil3294
    @rakakhairil3294 4 ปีที่แล้ว

    Is it possible to use freezed with JsonKey annotation?

  • @haidernaqvi87
    @haidernaqvi87 ปีที่แล้ว

    waiting for bLOC with Freeze

  • @TheJaniable
    @TheJaniable 3 ปีที่แล้ว

    🔥🔥🔥🔥🔥

  • @frozenspirittv
    @frozenspirittv 4 ปีที่แล้ว +1

    Pleaaaase please please please make a tutorial using Freezes with flutter_bloc 🤞🙏

    • @frozenspirittv
      @frozenspirittv 4 ปีที่แล้ว

      Also, great tutorial! Much appriciated!

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +4

      I'm just preparing a series where we will use it.

  • @uditswaroopa5809
    @uditswaroopa5809 4 ปีที่แล้ว

    at 8:02 you wrote _$User what is the meaning of _$ anyone??

  • @9876Hossam
    @9876Hossam 4 ปีที่แล้ว

    I know you have a busy schedule but any expectations about the release date of the series you said you had in the works?

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว

      I just finished implementing one core part of the project. I hope to get the project done by the end of the week and then I'm off to making the actual articles and videos.

    • @9876Hossam
      @9876Hossam 4 ปีที่แล้ว

      @@ResoCoder Best of luck, Matt. I'm so excited for it, your tutorials are the best out there 💙

  • @samsurya283
    @samsurya283 4 ปีที่แล้ว

    Bro can u do an tutorial for admob reward vedio .....plzzz.........love from India ❤️

  • @DavidSmith-ef4eh
    @DavidSmith-ef4eh 3 ปีที่แล้ว +1

    cool and all, but makes the code more confusing. Imagine if you don't know about freezed and browse someone's code who is using it. You'll spend 1h reasoning about (probably 36 minutes watching this video). Maybe it's better if dart doesn't support everything.

  • @shahidurrahmantushar21
    @shahidurrahmantushar21 3 ปีที่แล้ว

    "flutter pub run build_runner watch --delete-conflicting-outputs" doesn't generate the files. It runs and succeeds. but with 0 output and (0 actions). what to do?

    • @ПажилойМаслач-э8м
      @ПажилойМаслач-э8м 3 ปีที่แล้ว +1

      try to create new project and repeat

    • @morapedimasima9753
      @morapedimasima9753 3 ปีที่แล้ว

      I had to watch another tutorial to find the solution, you need the freezed_annotation package in the pubspec.yaml file and also change the @immutable in the freezed_classes.dart file to @freeze and import the freeze_anotation package into that file. Hope this helps

    • @soulstonefilms
      @soulstonefilms 3 ปีที่แล้ว

      @@morapedimasima9753 I m having the same issue, but not able to resolve it via your solution. Can you share the link to tutorial, maybe i m missing something else

    • @soulstonefilms
      @soulstonefilms 3 ปีที่แล้ว

      I added part 'yourclassname.g.dart' and ran the command. this worked for me, 2 files were generated, i deleted the .g.dart file that got generated.

    • @morapedimasima9753
      @morapedimasima9753 3 ปีที่แล้ว +1

      @@soulstonefilms I watched this video th-cam.com/video/pI6cXMmXBkA/w-d-xo.html&ab_channel=RobertBrunhage . Just make sure you running the latest version of flutter and also update the other 3 packages that are required and should be up to date. if that doesn't work then try and read the documentation here pub.dev/packages/freezed
      It also helped me understand more about what's happening.

  • @GabrielCosta-xr5vr
    @GabrielCosta-xr5vr 4 ปีที่แล้ว

    Sadly there is an issue with build runner that it doesn't see other files .part. Because of that isn't possible to use mobx observables of generated classes. And I'm using mobx for state management :/

    • @remirousselet6867
      @remirousselet6867 4 ปีที่แล้ว +2

      It should work actually. Freezed doesn't rely on part files.

    • @remirousselet6867
      @remirousselet6867 4 ปีที่แล้ว +1

      I've just tested to make sure.
      I can confirm that it does indeed work.
      To begin with, that's the reason why Freezed uses `*.freezed.dart` instead of `*.g.dart`

    • @GabrielCosta-xr5vr
      @GabrielCosta-xr5vr 4 ปีที่แล้ว

      @@remirousselet6867 woooow! Great! Thank you for that! Now I'll use it!

    • @FilledStacks
      @FilledStacks 4 ปีที่แล้ว

      @@remirousselet6867 Can we make the generated files go into a different folder automatically?

    • @remirousselet6867
      @remirousselet6867 4 ปีที่แล้ว +1

      ​@@FilledStacks Not with the part keyword. It should be feasible by relying on `import` instead of `part` though.
      But you can make that change yourself using the build.yaml and a few extra steps

  • @vladislavkomelkov7451
    @vladislavkomelkov7451 2 ปีที่แล้ว

    Why you call map a json?

  • @francescofreddi4374
    @francescofreddi4374 4 ปีที่แล้ว

    i have problem for dev_dependencies structure:
    dev_dependencies:
    --flutter_test:
    ----sdk: flutter
    --build_runner:
    --freezed: ^0.10.4
    --json_serializable: ^3.2.5
    - is a space, or tab
    whit that structure pub get tell me:
    Error on line 35, column 3 of pubspec.yaml: A package may not list itself as a dependency.
    pub get failed (65; ╵) 35 │ freezed: ^0.10.4
    Somebody can help me, please?
    francyfre

    • @francescofreddi4374
      @francescofreddi4374 4 ปีที่แล้ว

      i try to solved with this structure:
      dependencies:
      flutter:
      sdk: flutter
      json_annotation: ^3.0.1
      meta: ^1.1.8
      freezed: ^0.9.3
      dev_dependencies:
      flutter_test:
      sdk: flutter
      build_runner:
      json_serializable: ^3.2.5
      flutter puckages get functions!!!!, BUT......
      freezed finisch with 0 outputs: Succeeded after 89ms with 0 outputs (0 actions)

    • @devorrahtester5439
      @devorrahtester5439 4 ปีที่แล้ว

      @@francescofreddi4374 Did you resolve your issue? When I run the pub run watch command it ends with:
      [INFO] Succeeded after 121ms with 0 outputs (2 actions)
      But the freezed_classes.freezed.dart file is not generated.

    • @francescofreddi4374
      @francescofreddi4374 4 ปีที่แล้ว

      @@devorrahtester5439 i am forgotren about :) :) :)

  • @MrREALball
    @MrREALball 4 ปีที่แล้ว +1

    Imagine if the developers of dart weren't so dumb with their "oh, but the programmers are so dumb (not us though), these neseted classes will only confuse them" nonsense.

  • @jasnamitrovic1650
    @jasnamitrovic1650 4 ปีที่แล้ว

    iOS developers needs to Google everything first

  • @michaelwhite5460
    @michaelwhite5460 4 ปีที่แล้ว

    # the following fixes a freezed dependency problem github.com/flutter/flutter/issues/63556
    dependency_overrides:
    analyzer: '0.39.14'

    • @AhmedAyman
      @AhmedAyman 3 ปีที่แล้ว

      or modify analysis_options.yaml:
      and add those lines :
      analyzer:
      exclude:
      - "**/*.g.dart"
      - "**/*.freezed.dart"