Flutter Bloc & Cubit Tutorial

Sdílet
Vložit
  • čas přidán 3. 08. 2020
  • 📗 Written tutorial & starter project 👇👇
    resocoder.com/flutter-bloc-cubit
    📧 Get Flutter news 📰 and resources:
    👉 flutter.education
    👨‍💻 Do you write good code? Find out now!
    resocoder.com/good-code-quiz
    Bloc is a well-known and established library when it comes to state management in Flutter. It promotes good practices such as immutability and it has one of the best ecosystems of supporting packages and documentation built around it. In spite of all these benefits, using the Bloc package is painful at times and the cause is none other than boilerplate.
    The version 6.0.0 and upwards of the Bloc package comes to make this library palatable to the masses! It gives you the ability to use a lighter version of Bloc called Cubit and removes a bunch of boilerplate.
    Go to my website for more information, code examples, and articles:
    ● resocoder.com
    Follow me on social media:
    ● / resocoder
    ● / resocoder
    ● / resocoder

Komentáře • 170

  • @h3w45
    @h3w45 Před 3 lety +77

    2:57 going over the sample project
    4:36 cubits vs other mutable state management
    9:34 BLoC vs cubit
    11:00 building app using cubit
    37:10 building app using BLoC

  • @samuelobe5714
    @samuelobe5714 Před 4 lety +39

    I'm a simple man. I see a new Reso Coder video, I click...

  • @h3w45
    @h3w45 Před 4 lety +41

    thank you for covering the latest version of BLoC.

  • @SEOTADEO
    @SEOTADEO Před 2 lety +2

    Thanks a lot for this good tutorial! I have been working part time for 6 months in a flutter project for a big IT company and never cared that much to understand this concept, but now I do and it makes everything a lot easier.

  • @jamesdim
    @jamesdim Před 4 lety

    You are the best source for bloc development! And always up to date!

  • @pedroricci1
    @pedroricci1 Před 4 lety

    Wow, great timing! Yesterday I was reading the documentation. Thanks!

  • @juan_chan
    @juan_chan Před 3 lety

    man, thats a really good explanation of this new feature, i dont even have a goods english skill and i completely understood what cubit and bloc is, thank you

  • @alex_moreno
    @alex_moreno Před 4 lety +8

    I love the simplicity of cubit.
    Thanks for sharing this and compare the differences
    You are awesome

  • @mostafafahimi4588
    @mostafafahimi4588 Před 3 lety

    This channel is best flutter channel ever. Watched a lot of bloc tutorials but non was helpful like this.

  • @oblakus
    @oblakus Před 3 lety +1

    Dude, thank you for this "eureka moment" that I just had!

  • @cristianbedoyavargas
    @cristianbedoyavargas Před 3 lety

    Thank you so much for explaining this. I was looking for this for a while!

  • @mohamad20208
    @mohamad20208 Před 5 měsíci

    This is the best explanation of the Bloc I've seen

  • @LeonardoCostaCoesta
    @LeonardoCostaCoesta Před 3 lety +1

    Thanks since from Brazil, man! Keep going the good job!

  • @raheemadamboev
    @raheemadamboev Před 2 lety

    Thank you so much! It really helped me start with Bloc and Cubit. It is really similar to Jetpack ViewModel and Kotlin Flow pattern which is amazing!

  • @kitkatv7150
    @kitkatv7150 Před 2 lety

    Great video tutorial👏!
    Thanks for formatting the vid to be straightforward. The website link helps so it can be easily followed.
    Looking forward to other awesome videos.

  • @amartyakhan4700
    @amartyakhan4700 Před 4 lety +1

    Thanks a lot for this video! An in depth video/tutorial series about connecting a Flask/Django backend with a Flutter app would be amazing

  • @edungdivinefavour6977
    @edungdivinefavour6977 Před 3 lety

    Man. You got a new subscriber!!!!!!!!!
    This was so good. It cleared every question i had
    Thanks!!!!!

  • @LeagueRandomPlayer
    @LeagueRandomPlayer Před 4 lety

    Great Video i was waiting for this, GREAT GREAT JOB THANK YOU!!!!

  • @fritzjimenez9109
    @fritzjimenez9109 Před 4 lety

    Finally a new bloc tutorial

  • @bryanmonsalvatge1696
    @bryanmonsalvatge1696 Před 3 lety

    Thank you for this video. Very helpful!

  • @ShadowInfest
    @ShadowInfest Před 3 lety

    Hey ResoCoder ;) Working on our app and needed to update Bloc. Thanks for this amazing video once again

  • @chanky262
    @chanky262 Před 3 lety

    Awesome tutorial, thats what i was looking for

  • @raunaksingh7512
    @raunaksingh7512 Před 2 lety

    Wow! This is a great course on Bloc library.

  • @yaseerahmed1325
    @yaseerahmed1325 Před 3 lety

    What an amazing tutorial. Easily the best👌👍

  • @semsax6862
    @semsax6862 Před 3 lety

    Just what I was looking for!!!

  • @TheJaniable
    @TheJaniable Před 3 lety

    Combined Cubit with Freezed.. and OMG what a result!

  • @thewallstreetchokra
    @thewallstreetchokra Před 3 lety

    best ever tutorial for beginners...SUBSCRIBED

  • @kartavyabagga
    @kartavyabagga Před rokem

    I guess now i can move forward to making a complete app. Thanks man!

  • @phianh4545
    @phianh4545 Před 3 lety

    Thanks for your instructions, I love the way you organized your youtube channel and linked to your website, I'm doing with Bloc and now the cubit just remove the state file, which means will save my time alot. Really want to work with you some day, Peace out mate

  • @abduraimoff3090
    @abduraimoff3090 Před 2 lety

    Thank you so much ! It helped me a lot

  • @programan6391
    @programan6391 Před 4 lety

    Great job, thank you.

  • @nawalhussein1891
    @nawalhussein1891 Před 4 lety +5

    You are an amazing teacher! Thank you. Bloc has been like a maze for me and you have helped me greatly in figuring it out. Thanks again.

  • @johncerpa3782
    @johncerpa3782 Před 4 lety +1

    Great video, thank you

  • @geraldcampana9296
    @geraldcampana9296 Před 4 lety

    thanks for the tutorial!

  • @jonahlehner3855
    @jonahlehner3855 Před 3 lety

    Another great video!

  • @FalStudio1234
    @FalStudio1234 Před 2 lety

    Awesome man, thanks a lot

  • @nicolasdupere
    @nicolasdupere Před 3 lety

    Great tutorials! Thanks

  • @mohad1062
    @mohad1062 Před 3 lety

    you are my hero man.

  • @thongtech1984
    @thongtech1984 Před 2 lety

    great work, thanks alot for your vids, you just saved my days.

  • @bensalkb6902
    @bensalkb6902 Před 2 lety

    I like your coding practices like organising files and stuffs

  • @akyna0wind
    @akyna0wind Před 2 lety

    bravo! excellent totorial!

  • @ahmedmaher-ez9xt
    @ahmedmaher-ez9xt Před 3 lety

    thank you so much for your time and effort :) i'm learning from you a lot every day ... planing to finish TDD after this i will make a my start up project using TDD and will apply to remote job :) i will tell you when i got a job that your are the main reason of it ^_^

  • @ethanhunt8316
    @ethanhunt8316 Před 4 lety

    Thank you so much, you are the best.

  • @emmanuelvedastus5218
    @emmanuelvedastus5218 Před 2 lety

    Thanks a lot for this tutorial you realy saved my day im already your subscriber

  • @Jdbluesky
    @Jdbluesky Před 2 lety

    Muchas gracias hermano!!

  • @peterwauyo2424
    @peterwauyo2424 Před 4 lety +2

    great explanations

  • @engmahmoudahmed1984
    @engmahmoudahmed1984 Před 2 lety

    Amazing thanks 😊

  • @mual77
    @mual77 Před 4 lety

    Good job!

  • @tiennghequyet1268
    @tiennghequyet1268 Před 3 lety

    thanks for the tutorial

  • @shrinivasmanjithaya2112

    Clear explanantions..thank you so much..

  • @hq_net
    @hq_net Před 6 měsíci

    Everything is beautiful 😊😊

  • @makymadi242
    @makymadi242 Před 4 lety

    Thanks Guy!!!

  • @Grovermol
    @Grovermol Před 4 lety +5

    Nice tutorial, i'm finally understanding cubit and bloc, thanks dude. By the way what theme did you use in VsCode for the tutorial?

  • @elistark9264
    @elistark9264 Před 4 lety

    This is what we are waiting for!

  • @ahmedelbaghdady
    @ahmedelbaghdady Před 4 lety

    very good i like your videos and i'm bloc fan like you thanks

  • @justconnor734
    @justconnor734 Před 3 lety +21

    @34:50 For "final weatherCubit = context.bloc();" it says "'bloc' is deprecated and shouldn't be used. Use context.read or context.watch instead. Will be removed in v7.0.0.
    Try replacing the use of the deprecated member with the replacement.". What is a good replacement for this code? Thanks
    EDIT for anyone interested its final weatherCubit = context.read(); intead

  • @amirsohail7284
    @amirsohail7284 Před rokem

    well explained

  • @karthikraja6577
    @karthikraja6577 Před 4 lety +4

    Finally bloc tutorial 👍👍👍👍👍
    How many more videos are there in the DDD flutter series ?? @resocoder

    • @ResoCoder
      @ResoCoder  Před 4 lety +5

      I think not more than 4.

    • @karthikraja6577
      @karthikraja6577 Před 4 lety +2

      @@ResoCoder eagerly waiting for them ! Take care and relax ! It's surely a hell of task to compile such a awesome course !
      Great effort bro 👍

    • @mibi2007
      @mibi2007 Před 4 lety

      @@ResoCoder really good tutorial, thank you so much Matt

  • @danarputra9181
    @danarputra9181 Před 3 lety

    For first time using Bloc is hard
    And now in this video i know how is Bloc is worked

  • @jimaustin3608
    @jimaustin3608 Před 3 lety +1

    In learning state management (for flutter/dart development), I’ve been through with the setState design and the provider package; now looking at the BLoC pattern.
    BLoC ‘feels’ like imposing imperative design on a basically declarative (reactive) system, where provider seems a better fit for the flutter declarative framework.
    I don’t have good/bad opinions about this yet, just interested the views of those more experienced with flutter/dart .

  • @easazade
    @easazade Před 4 lety +3

    thank you for this my code just became so smaller using functions instead of events

  • @user-gp1tr4kr4d
    @user-gp1tr4kr4d Před 4 lety +1

    Cool !

  • @akshaymarathe8133
    @akshaymarathe8133 Před 4 lety +2

    Sir please make a video of using bloc pattern along with json API

  • @humanontheinternet6510

    finally 🙌

  • @davdev1695
    @davdev1695 Před 2 lety

    Thank you for this amazing tutorial. It explains really well the topic!
    Just one question: for every Cubit/Bloc in a project the states are usually Empty, Loading, Loaded & Error or there are other cases?

  • @thedudeabides8637
    @thedudeabides8637 Před 3 lety +2

    Thank you for this. As a noob developer, after really diving into this video and going through it a few times over a couple days, I FINALLY feel like I actually understand how Bloc/Cubit works and how to implement them into the first app that I'm building myself. I made major breakthroughs in my app after it all clicked for me with this video. And thank you for doing a tutorial on the updated Bloc/Cubit so soon after the major change, not much else out there that's up to date
    Lots of great flutter tutorials out there, Reso Coder rules them all. Thanks for the great work.

  • @Fly16
    @Fly16 Před 3 lety +1

    amazing tutorial! by the way what's the font you are using?

  • @samiral7423
    @samiral7423 Před 3 lety +1

    please teach TDD with cubit

  • @HashemRC
    @HashemRC Před 3 lety +2

    always thanks for you quality tutorials. what's real difference between Bloc and Cubit? when should we use Cubit?

  • @mallikarjunreddy5229
    @mallikarjunreddy5229 Před 4 lety

    Hey Matt, great explanation. Could you please help me out on how to generate boilerplate code like bloc extension.

  • @RohithkannaDuraiswamy
    @RohithkannaDuraiswamy Před 4 lety

    Woah. Can't believe this is on flutter dev LinkedIn page too, lol

  • @Ryszardenko
    @Ryszardenko Před 3 lety

    Awesome! Thanks!
    Can you explain how toi use freezed with State classes?

  • @vladyslavmi
    @vladyslavmi Před 2 lety +2

    *After v6.1.0, both context.bloc and context.repository are deprecated in favor of **context.read** and **context.watch*

  • @axehai
    @axehai Před 3 lety +3

    Hey, great work as always, I wanted know why didn't you suggest using Equatables for checking equality, like in TDD tutorials?

    • @socinety
      @socinety Před 2 lety

      Can I use equatable package along with cubits without overriding equality?

  • @chinazaogwo5046
    @chinazaogwo5046 Před 4 lety +1

    Awesome tutorial. Please can you send the plugins you use for flutter development with vs code

  • @TestingQuebec
    @TestingQuebec Před 4 lety +1

    Thanks for the tutorial. I'm curious as to how the '^' works in the hashCode override for the Weather class? 'cityName.hashCode ^ temperatureCelsius.hashCode'

  • @srihariayapilla4233
    @srihariayapilla4233 Před 3 lety

    Which vs code theme is thhis. Looks sooooo good.

  • @i.k.shaikh3772
    @i.k.shaikh3772 Před 3 lety

    Hey Thanks for this brightening tutorial, i am trying to pass an index of files in a directory to a listview, could you help me with that ??

  • @jktan5793
    @jktan5793 Před 3 lety

    Hi @reso coder
    I have question about GetX, I am not sure what do you think about that library.
    thanks for sharing your knowledge and opinion.

  • @sacrac1
    @sacrac1 Před 3 lety

    I have a question, if I want to save the data that comes from the weather api in a database (sqflite), at what moment of the emit should I call that method to save and how would it be?

  • @barsidemen5208
    @barsidemen5208 Před 3 lety

    Thanks Matej ! Is there a benefit of using xxxBuilder() widgets (such as BlocBuilder()) in a stateful widget? I think they are Stateful within themselves already, so what's the reason to wrap them in a stateful widget, too?

  • @dalriada33
    @dalriada33 Před 3 lety

    One question: is it important to provide the FakeWeatherRepository from outside to the Cubit through its constructor? Is there some disadvantages if I create an instance of it inside the Cubit?

  • @user-he9nw2qt2i
    @user-he9nw2qt2i Před 4 lety

    Wow!!~~~👍👍👍👍👍

  • @aserlink
    @aserlink Před 3 lety

    How do you override equality using freezed? I have read the written tutorial but didnt find much help about this part

  • @franfox
    @franfox Před 3 lety

    Nice tutorial! I would like to ask you guys why was it not necessary to dispose the bloc in this case? thanks!

  • @arifikhsanudin9724
    @arifikhsanudin9724 Před 4 lety +1

    Hi Reso

  • @pedrosanchezroca181
    @pedrosanchezroca181 Před 3 lety

    how would you put data in the InitialState for the cubits?...like if I want data loaded at the beginning.

  • @bmsrangel1
    @bmsrangel1 Před 3 lety

    Hey, man! How are you?
    First of all, congratulations for this tutorial! It helped me a lot with BLoC understanding!
    Dude, what is the best way to fix the warning "Close instances of `dart.core.Sink`."? I understand this warning helps to avoid memory leak due to opened streams left behind. I noticed that in Bloc code there's a close method. In this case, how do we handle it? Do we need to close the stream manually? Or it will be executed automatically?

  • @ederortega9606
    @ederortega9606 Před 4 lety

    your are the best, please examples googlemaps type uber

  • @efesahin7168
    @efesahin7168 Před 3 lety

    hey why did not use listener in weather_bloc.dart page ? In previous video which is counter app, we used to constructor with listen function.
    i mention that:
    CounterBloc() {
    counterEventController.stream.listen(mapEventToState);
    }
    like this.

  • @aduhglupa
    @aduhglupa Před 2 lety +1

    Thank you for the tutorial. Can you show me the code using the "freezed" package?

  • @landrygagne
    @landrygagne Před 4 lety +2

    Great tutorial, thanks a lot! I was SOOOO depressed to see my app broken by flutter_bloc version upgrade. BTW, 6 major versions within 8 months for the flutter_bloc package, am I the only one shocked? Any chance to get some kind of stability for this package in the future? Otherwise you will be obliged to make a new tutorial every month!!!

    • @ResoCoder
      @ResoCoder  Před 4 lety +1

      Most of the changes are quite minor but by following the rules of semantic versioning, every breaking change has to automatically bump the major version number. I'm not opposed to doing tutorials though 😀

  • @efesahin7168
    @efesahin7168 Před 3 lety

    what is the differences between cubit and bloc? why we use cubit if we deleted or switched them ?

  • @1234matthewjohnson
    @1234matthewjohnson Před rokem

    can the equatable package not be used with cubits rather than something like freezed?

  • @jktan5793
    @jktan5793 Před 4 lety

    With Cubic, how can I get the current state ? for the pagination purpose

  • @snaidher5
    @snaidher5 Před 3 lety

    Hi, please could You Make a login example using cubit, I don't know how to validate the form.
    Thanks in advance

  • @astronaute
    @astronaute Před 4 lety +2

    There is no need to add "bloc" in pubspec.yaml, it’s pulled automatically with "flutter_bloc".
    Also, when using "const" constructors, you shouldn’t use "new" with them, it defies the (already limited) purpose.

    • @francoprofeti142
      @francoprofeti142 Před 3 lety

      I was thinking about the second thing while watching the video

  • @snaidher5
    @snaidher5 Před 3 lety

    Hi , please could you make an example of using firebase with cubit, please!

  • @StefanoSaitta
    @StefanoSaitta Před 4 lety +1

    Great content as always, in your opinion it makes sense to mix cubit and bloc in your app? What a bloc can do that a cubit can't?

    • @ResoCoder
      @ResoCoder  Před 4 lety +1

      Thanks, Stefano! Bloc can, for example, transform its incoming events with debounceTime from RxDart. This is useful for auto-search where you don't want to necessarily trigger an API call for every inputted character.

  • @Alex-dg2mb
    @Alex-dg2mb Před 3 lety

    If the block consumer only defined handling the case where the state is weatherloaded in the builder function (only the weatherror state was handled in the bloc listener), how did the UI update on weatherloaded once you searched for weather second time ? This is during the cubit section of this talk.