#10 - Bloc State Not Updating - Comparing 2 objects in Dart, Equatable Package, How to Fix Issue

Поділитися
Вставка
  • Опубліковано 11 гру 2024

КОМЕНТАРІ • 100

  • @Flutterly
    @Flutterly  3 роки тому +5

    Hello, everyone!
    The entire course is now live on Udemy too, get it while it's hot --> www.udemy.com/course/bloc-from-zero-to-hero/?referralCode=E689592633984B34DBEF
    Also I have just managed to finally finish the entire BLoC - From Zero to Hero Complete Course, based on this tutorial series. You can check it out here -> ua-cam.com/video/THCkkQ-V1-8/v-deo.html

  • @bayanhoms8532
    @bayanhoms8532 6 місяців тому +1

    till 2024, there is no best tutorial elaborates bloc concepts clearly as this tutorial. Keep up going!

  • @muhammadshahzadakram7742
    @muhammadshahzadakram7742 4 роки тому +13

    WCKD is a lifesaver 😍. I was so frustrated with the State Not Updating thing and Now I know the correct way to do it. I am glad I had notifications turned on 🙌.

    • @Flutterly
      @Flutterly  4 роки тому +2

      Haha, thanks! 🌟 Glad I could help you understand more!

  • @opressedrage
    @opressedrage 3 роки тому +2

    This video is a lifesaver i was mutating the state the whole time and asking my self why the UI not working
    Thanks man for saving me you desurve my like and subscribe ❤

  • @Tokieejke
    @Tokieejke 4 роки тому +2

    you content so underrated. so i decide to write comment with nice length to support you. keep going u do a great work for all flutter community!

    • @Flutterly
      @Flutterly  4 роки тому

      Thank you so much 😀

  • @williammutua
    @williammutua 4 роки тому +2

    These are by far the most informative Flutter state management tutorials, looking forward to more content from you.

    • @Flutterly
      @Flutterly  4 роки тому

      Thank you so much, man! Really appreciate it!

  • @iNFiNiTY-yf3rk
    @iNFiNiTY-yf3rk 4 роки тому +2

    Duddeeeeeeeee 🔥🔥🔥🔥🔥🔥🔥 I am so much grateful to you. ❤️ Much much love from India. You are a life saver.

    • @Flutterly
      @Flutterly  4 роки тому +1

      Thank you so much, mate, really appreciated!

  • @askarmus
    @askarmus 3 роки тому +1

    Thank you for these great tutorials. I spent so much time to understand and deal with unexpected output/errors, finally, thises video cleared ally my misconception of the flutter_blok package. keep it up.

  • @MikeKeiler
    @MikeKeiler 4 роки тому +12

    By far one of the most useful tutorial series I've every watched for flutter! 💙 Please keep up this great work at this excellent quality. I've "binge watching" this tonight, could not stop at all 😉
    Personally I'm using BLoC now for more or less one year, also productive, but still, there are so many helpful informations in your tutorials.
    Some interesting topics for me (and I can imagine also for other people) would be:
    * Explain why the class in a bloc state is "abstract" and whats the difference between abstract and non abstract?
    * Is it okay to use context.watch() really often in one page? like 20 - 30 times? Or does this impact the performance of an app?
    * Should I now generally prefer using context.watch over a BlocBuilder?
    I can't wait to get to the next tutorial, and maybe soon to the Bloc tutorials with Event Streams.
    Thanks a lot for sharing your knowledge!

    • @Flutterly
      @Flutterly  4 роки тому +8

      Wow, such an amazing feedback! Thank you so much, mate! I really appreciate it! I can quickly answer to some of your questions, since they don't really need an entire video. So, let me begin, haha.
      1. Abstract class is, like is name is implying, something abstract. It's not really "detailed", it's something blurry. It's like a global type of class, from which other small classes derive. In your case, you saw in this tutorial that when we have only one Settings State there's no need to create an abstract class, but when we'll have multiple possible states, it's a good practice to create a WeatherBloc with an abstract WeatherState just so the multitude of states will be "small part" of the global WeatherState. You can find more information about this by searching Google for Dart abstract classes.

    • @Flutterly
      @Flutterly  4 роки тому +9

      2 and 3 - Context.watch() is just an addition to BlocBuilder. I'm not a big fan of these new methods, I'd still use Bloc Builder everywhere. In a big application I don't think you would have to use Bloc Builder more than let's say 5-10 times inside a page. If that number exceedes, you should think about partitioning the page into multiple small pieces, since having a ton of code inside a single page will drastically decrease your efficiency.

    • @MikeKeiler
      @MikeKeiler 4 роки тому +1

      @@Flutterly Thank you sir 🤗

  • @batuhankrbb
    @batuhankrbb 3 роки тому +2

    You are the besttttt. I wish I could give you Giulia Quadrifoglio :D

    • @Flutterly
      @Flutterly  3 роки тому

      Haha, thank you so much! ✨

  • @abhishekreddy8953
    @abhishekreddy8953 10 місяців тому

    Thanks a lot sir, for educating us with your valuable content, even now {after 3 years}, It was a treasure for us

  • @aurelagbodoyetin3321
    @aurelagbodoyetin3321 4 роки тому +1

    Wckd is back 💥🔥🔥

  • @TalksFromCar
    @TalksFromCar Рік тому

    Your content is too good man!! Thank you so much!! You are life saver!!

  • @joshuanwokoye
    @joshuanwokoye 7 місяців тому

    Meen, this video releaved me of several hours of trouble

  • @ddbonpc
    @ddbonpc 4 роки тому +3

    Thanks a lot ! this is really a great way of explaining how things work !

  • @abdullahalamodi5455
    @abdullahalamodi5455 4 роки тому +3

    excellent work man, keep going

    • @Flutterly
      @Flutterly  4 роки тому +2

      Haha, haven't even posted this yet, glad you could find it hidden in the Playlist. Will post it tomorrow and thanks! I will

    • @abdullahalamodi5455
      @abdullahalamodi5455 4 роки тому

      @@Flutterly
      Could you make full example about what you explained not just a tips of code
      I mean example that contains crud operations dealing with server
      It's not an example
      It's a small project 😅

  • @rickycoates3003
    @rickycoates3003 2 роки тому

    I don't get it why this one has only 500 like xD, in mycase if I didn't watch this video, I swear I was 100% going to modify the state directly coming from js background

  • @dutnorshi
    @dutnorshi 4 роки тому +12

    Thanks for this great tutorial! BTW, what extensions do you use in the vscode for equality and copyWith generation?

    • @Flutterly
      @Flutterly  4 роки тому +7

      It's called Dart Data Class Genetator (Beta), thanks, I'll pin this comment so that everyone will know.

  • @j3ns
    @j3ns 4 роки тому +3

    Thanks for this awesome video! I am looking forward to the next ones 😀

    • @Flutterly
      @Flutterly  4 роки тому +1

      Thank you so much! ✨

  • @rohitprajapati5606
    @rohitprajapati5606 3 роки тому +1

    This was really amazing. Thank you so much flutterly.

    • @Flutterly
      @Flutterly  3 роки тому

      You're welcome! Thank you!

  • @MrAidooyaw
    @MrAidooyaw 4 роки тому +2

    thank you very much, u have really made me understand equatable

    • @Flutterly
      @Flutterly  4 роки тому +1

      I am so glad I did, you're welcome, mate! 🌟

  • @yanischetouani7392
    @yanischetouani7392 4 роки тому +1

    keeeeeep posting pleasseee !!!! OMG you're a lifesaver ! and also if you can start building an e-commerce app from scratch ,it would be very useful .
    thanks man !

    • @Flutterly
      @Flutterly  4 роки тому +1

      Thank you so much! I will!

  • @islomkhujaakhrorov6668
    @islomkhujaakhrorov6668 3 роки тому +1

    Awesome Video )

  • @mgkaungenglish453
    @mgkaungenglish453 4 роки тому +1

    Thanks for this great tutorial.

    • @Flutterly
      @Flutterly  4 роки тому +1

      You're welcome! Thanks! 🌟

  • @dgodiegomartins
    @dgodiegomartins 4 роки тому +1

    Excellent, thanks!!

    • @Flutterly
      @Flutterly  4 роки тому

      You're welcome, mate! 🌟

  • @jjsportify77
    @jjsportify77 4 роки тому +5

    Hey thanks for your wonderful tutorial, but I have got a question.
    Should we use equatable along with copyWith function for comparing our states? I am not sure why Equatable is neccessary here if Dart compares the instance by object instead of values by default. Whenver we create a new state instance by copyWith function, wouldn't Dart be able to compare already? It seems like it works as charm even if you didn't extend equatable from the tutorials above. Thank you

    • @Flutterly
      @Flutterly  4 роки тому +3

      Man, as I stated inside the tutorial, copyWith and Equatable are 2 completely different things. If you want to compare two instances by value, you should extend Equatable or override the equal operator (==) as you wish. The copyWith method has nothing to do with comparing stuff. It is mainly used for creating a new instance from an already existing one, by mentioning the parameters that are changed in the new one compared to the old one (see the code in the tutorial).

  • @farseenabdulsalam6246
    @farseenabdulsalam6246 3 роки тому +1

    Concise and clear 💙
    Could you make a video on InheritedWidgets? Or how does Provider.of() cause a widget deep down the tree to be rebuilt while keeping its parents intact?

  • @cveklica
    @cveklica 4 роки тому +1

    So much easier to understand when there are pictures 😁
    Really enjoyed it!
    Just one question => Must we use both copyWith and Equatable props together, or is only Equatable enough?

    • @cveklica
      @cveklica 4 роки тому

      or just copyWith without Equatable because it works?

    • @Flutterly
      @Flutterly  4 роки тому

      Thanks. It's either one or another, never both. Basically, Equatable is a simple version of copyWith() and hash() all together. I suggest that you only use Equatable. Thanks!

    • @yanischetouani7392
      @yanischetouani7392 4 роки тому +1

      @@Flutterly why never both ? in some Felix Angelov projects he used Equatable and copywith at the same time ! take a look here : github.com/felangel/bloc/blob/master/examples/flutter_firebase_login/lib/login/cubit/login_state.dart

    • @Flutterly
      @Flutterly  4 роки тому +1

      Sorry, I meant saying that you should use either Equatable or the override of the equality operator, never both (which makes sense) . My mistake, I'm sorry. I must've been tired when I replied. Sorry again. And yes, you can use copyWith with Equatable as they have nothing in common. They both have different purposes.

  • @pedrodelacruz2369
    @pedrodelacruz2369 4 роки тому

    Some interesting topic for me :
    - Bloc Observer
    - Bloc Testing
    - Injectible
    - The initial Flow of an app, using bloc to Navigate between Onboarding, Login, Home

    • @Flutterly
      @Flutterly  4 роки тому +2

      Mate, everything you mentioned is already covered in my tutorial series.

  • @Add0w
    @Add0w 4 роки тому +1

    perfect , thanks bro.

  • @adnanalshami3751
    @adnanalshami3751 4 роки тому +1

    Amazing as always.
    BTW, what programs/tools do you use to edit these videos?

    • @Flutterly
      @Flutterly  4 роки тому

      I use multiple products like Videoscribe and Premiere Pro

  • @manthankhandale23
    @manthankhandale23 3 роки тому

    Thank you so much I was stuck for hours trying and later realized that my props was empty 😭

  • @jontysingh4334
    @jontysingh4334 2 роки тому

    Great tutorial, I understood all of your videos, I have one doubt Didn't we were sending same state in previous counter examples then how we were getting new state we didn't use copywith method in counterState, how it was working fine?

  • @ramkishoreprajapati1325
    @ramkishoreprajapati1325 4 місяці тому

    It's valuable content.

  • @mallikarjunreddy5229
    @mallikarjunreddy5229 3 роки тому +1

    Hi Flutterly, Am facing issue with state update using bloc pattern. I have followed all the possibilities as you mentioned in the video like extending equatable and declaring all the properties in the state. but still am facing the same issue. Could you please help me out on this some how if possible.

  • @MrEricv75
    @MrEricv75 4 роки тому +1

    Nice videos, what did you use for making it please ?

    • @fredikruger5690
      @fredikruger5690 4 роки тому

      Yes its great : What do you use @Flutterly please ?

    • @Flutterly
      @Flutterly  4 роки тому +1

      I use a combination between Videoscribe and Premiere Pro. 👍

  • @pedrodelacruz2369
    @pedrodelacruz2369 4 роки тому

    Thank You!!!! Really usefull

  • @abrorbobomurodov2361
    @abrorbobomurodov2361 4 роки тому +1

    thank you bro,

  •  Рік тому

    i do want to emit 2 states tho
    example. i delete with 1 button 2 objects,
    for each deleted object i want to show a bottom sheet for the user to review the object, so i emit 2 objects so 2 bottom sheets show up.
    unfortunately the second emition closes the first bottom sheet.

  • @navarasan8264
    @navarasan8264 4 роки тому +1

    I have a doubt.. all these states have only one or two variables and passed inside constructor from cubit. Consider if a state contains 10 variable and those 10 are not updated and used at same time. At each scenario a single state variable is updated. How can we do that?

    • @Flutterly
      @Flutterly  4 роки тому

      With the copyWith method, you didn't pay enough attention to what I mentioned in the tutorial man.

    • @Flutterly
      @Flutterly  4 роки тому +1

      If you'd have a class A with var a, b, c, d, e, f initilaised in the constructor, then you would have a copyWith method as I did in this tutorial from where you can class classObject.copyWit(only mention the parameters you want to update here)

  • @mcop1
    @mcop1 6 місяців тому

    I am extending Equatable in my state class AND emitting a NEW state but still nothing happens, what is the issue in this case?

  • @MuhammadRizki-cl3ru
    @MuhammadRizki-cl3ru Рік тому

    hey thank you for make this videos
    but i have question
    i have case that i need change frequently list in my app
    but when i emitting the state of my list i need to move the value to the new list because list is mutable
    i try to not put my list inside props but like in your video i need to put all my field inside list porps
    is there a way that i can still emitting my list without move to new list but still extends equatable ?

  • @quicksketch1617
    @quicksketch1617 4 роки тому

    Thank you. I saw some examples using equatable but no one explained. I don't understand why use : super. I read something about initialize constructor, if compare with typescript or python or java this kind of constructor exist or it's just dart?

  • @pedrodelacruz2369
    @pedrodelacruz2369 4 роки тому +1

    What extensions do you use for the folder theme?

    • @Flutterly
      @Flutterly  4 роки тому +1

      The last tutorial of this series will be about everything I use, I can't really remember which icon pack it is, but I'll let you know then.

    • @pedrodelacruz2369
      @pedrodelacruz2369 4 роки тому

      @@Flutterly Thank you mate!!

  • @adarshagnihotri5047
    @adarshagnihotri5047 4 роки тому +1

    Thanks.
    Do you have any real project example as I am not able to perform bloc on real project.

    • @Flutterly
      @Flutterly  4 роки тому

      I will start a new tutorial series regarding real world examples and apps with bloc

    • @Flutterly
      @Flutterly  4 роки тому

      Equatable is comparing by value, instead of comparing by reference

  • @makisetakashi
    @makisetakashi Рік тому

    How to open pop up generator like that on vscode macos?

  • @r4f43ll
    @r4f43ll 3 роки тому

    hey, @Flutterly is there anything wrong with changing appNotification/emailNotification bool variables with code like:
    emit(state.copyWith(emailNotification: !state.emailNotification));
    discarding newValue altogether and making toggleNotification methods parameterless?

  • @keithbacalso9433
    @keithbacalso9433 3 роки тому

    How you get those Generate generate things? when you press command + . because I cant get those Generate things.. all I get is Wrap wih BlocBuilder, BlocSelector etc.. etc... no wrap with.... :(

    • @r4f43ll
      @r4f43ll 3 роки тому +1

      Data Class Generator extension

  • @krichenekhaireddine4193
    @krichenekhaireddine4193 2 роки тому

    hello i think putting const when declaring the instance solve the problem instead of using the equitable package

  • @aakashr79
    @aakashr79 3 роки тому

    Perfect. And here I was thinking I'm the crazy one in my team to think mutating an object isn't the way to modify the sate.
    I do have a question though. If you have a list of objects that could be re arranged and you want the state of all the objects and its values maintained throughout the app, what would be the correct way of doing so? I use GetX and I'm trying to incorporate good architecture with it. I used stream subscriptions in the sub controllers(blocs) to update when the values in the parent bloc changes. Problem is, that if the list is re ordered, the listener of that list is updated, but the listeners of the individual objects are not triggered since they are entirely new instances which were never subscribed to. What would be the correct way to approach this?

  • @정지헌-b9u
    @정지헌-b9u 4 роки тому

    Great vid WCKD, your lessons are always great. I have a question for you. I did some experiments with the Equatable package, listing the props with the this.* form. The app seemed to work fine although I'm not sure quite why. I am guessing that since Equatable is used to compare Objects, then parameters contained in the instance works the same. I dunno for sure though... Do you have some clues?

    • @Flutterly
      @Flutterly  3 роки тому

      "this.variable" is referring to the specific variable used inside the class. If it works fine for you, then it's ok!

  • @fredikruger5690
    @fredikruger5690 4 роки тому

    What tool do you use for your video / drawing plz ?

  • @hc-ec6bm
    @hc-ec6bm 3 роки тому

    I love your contents but I have watched this video 2 times, but still didn't understand what Equatable stands for. How can I use in real lif scenario?

  • @keithbacalso9433
    @keithbacalso9433 3 роки тому

    Also you said "Copy the content from the previous one to the new state"
    so you mean if the "previous state is ONE"..... then.... "copy that prevoius state ONE to the new state" so now "the new state is ONE" ? I dont get it .. I would appreciate and understand if you give example of prev state and the new state :)

  • @temofey7707
    @temofey7707 2 роки тому

    if you have a list as class field and emit not update a state - you must put FIELDNAME.hashcode in state props.
    i fix this bug over 3 hours

  • @9997eman
    @9997eman 2 роки тому

    One thing he didnt fully explain is why A cannot be equal to B. Even if they are both instances of myclass. The reason is they are not the SAME instance. If class is a blueprint then A and B were created with the same blueprint but they are not the same instance.

  • @ghaithchamieh7087
    @ghaithchamieh7087 3 роки тому +1

    I would say this is literally from 0 to hero BLoc tutorial.