Flutter: State Management with Provider

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

КОМЕНТАРІ • 155

  • @dellaian
    @dellaian 5 років тому +121

    8:52 Keep in mind that in Provider 3.0.0 (the latest) the "notifier" have been changed to "value", eg: ChangeNotifierProvider.value(value: CounterBloc())

    • @paulhalliday
      @paulhalliday  5 років тому +1

      Thanks for this. I’ll keep it in mind for an updated video.

    • @dellaian
      @dellaian 5 років тому +2

      You also don't need to use "new" to implement any widget in the tree.

    • @paulhalliday
      @paulhalliday  5 років тому +2

      I recently learned that too, cheers!

    • @dellaian
      @dellaian 5 років тому +3

      @@paulhalliday You could also use: ChangeNotifierProvider(builder: (context) => CounterBloc()), This will avoid version problems for now, or it might be better to have a version lock into your pubspec.yaml file for future tutorials, so people who watch will dive into the package and see the changes for themselves. (Just trying to be helpful)

    • @putinninovacuna8976
      @putinninovacuna8976 5 років тому +1

      hey u nerdy can u explain me what's the difference between consumer and provider.of() ?

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

    I always like random people who teach like this. Straight forward explanation and examples,

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

    The best video I have ever seen on flutter State management using Provider package. Thanks a lot.

  • @SamuelGuebo
    @SamuelGuebo 5 років тому +1

    Definitely the best guide I've watched so far on Flutter's Provider. It's well explained and straight to the point. Thanks Paul!

  • @PurvikRana
    @PurvikRana 5 років тому

    Simply the best to understand what is provider and how it's working in flutter.

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

    Excellent tutorial. The main principles is explained for a rapid understanding of the pattern.

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

    hey paul, saved my day. Best explanations are often simple and yours is one of them. keep it up.

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

    Very well written and recorded explanation. Good job! You should definitely pursue this path.

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

    Yes thank you for this bro. Because I am a RN dev but I want to switch to flutter world and finding the best state management nice one

  • @paulbaker2499
    @paulbaker2499 5 років тому +45

    Thank you for the short article. However - I would just like to point out :
    a. This has nothing to do with BLOC. What you have shown is basically MVVM. I would be inclined to therefore rename your components and drop the BLOC annotations as this may become confusing to dev's who are just starting Flutter and believe they have now learnt Bloc. Bloc is reactive and Stream-based. Provider is simply inherited widget on steroids.
    b. For simple applications - using a provider at the root of the app is okay. For more complex apps with very large widget trees - I would not recommend adding every single provider at the root of your app, both for performance & manageability reasons. Additionally as of v3 of provider , ProxyProvider was introduced which may lead to lots of proxyprovider stringing when we try and inject into objects within the widget tree that do not contain a build context. Thus, in my experience , it is best to not provide a global Provider at the root of the app but to instead inject Provider on a per-case basis, use sparingly where it is needed , remember Provider.of(context) in your Build() methods is not a cheap operation - especially if your widget tree is very large. FWIW my apps are reactive, I use RxDart and Bloc throughout and a hand rolled Provider class..

    • @quicktips3858
      @quicktips3858 5 років тому

      Just another copy and paste tutorial....

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

      why not show us practically how you do it? Paul Halliday is trying his best to show us all he knows, u claim to know but you not showing us anything!!!

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

      > remember Provider.of(context) in your Build() methods is not a cheap operation
      It's because you're probably not using it correctly. Provider.of() is indeed not cheap, because you rebuild the whole widget tree.
      Use it with (listen: false) parameter, to dispatch actions without subscribing to changes.
      Use Consumer() for optimization which has a 'child' parameter to exclude child from rebuild.
      You can optimize even more, using Selector() to subscribe selectively only to those store changes you want to watch.
      I hope this helps.

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

      @@sergey_molchanovsky say I have a widget which has 3 children. But only one of those 3 widgets needs the value from my ChangeNotifierProvider. So if I use
      final abc = Provider.of(context) in my parent widget's build function, will it cause all 3 children widgets to be rebuilt or only the one where I'm using the provider?

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

      @@ad9633 yes, it will. That's why as a mentioned before, you should use Consumer and wrap only 1 child you need to rebuild. Or use Provider.of inside of this child instead of parent.

  • @georgeruellan
    @georgeruellan 5 років тому +5

    I had to watch this twice but I've got my head around it now. Thank you!

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

    Nice & simple explanation. Thanks Paul!

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

    Best video on flutter provider.

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

    well explained, easy to understand. do you have video of implementing bloc for login state management?

  • @fernando_her85
    @fernando_her85 5 років тому +4

    Amazing tutorial, thank you! Keep this videos coming Paul!, you got a new subscriber

    • @paulhalliday
      @paulhalliday  5 років тому +1

      Thanks for watching! I'm excited to bring more Flutter videos as I continue to learn. 🙌🙌🙌

  • @rikyriky966
    @rikyriky966 5 років тому +17

    Wow this is simply the best video of state management in Flutter. I can now clearly understand the concept of Provider.
    A tiny question: is it a good approach to wrap the whole app with the multiprovider and insert providers into provider=[ ] as you did in the video?
    Of course, this way I can simply call any bloc from anywhere of the app since it’s all covered. Also I can add new blocs to the list and they will also be available immediately for the whole app.
    Does that have a disadvantage?

    • @AndreasFelix
      @AndreasFelix 5 років тому +2

      Would be interesting to get an answer on this.

    • @RudeboyJackson
      @RudeboyJackson 5 років тому +1

      +1

    • @Tianex
      @Tianex 5 років тому +1

      +1

    • @samansalehi1496
      @samansalehi1496 5 років тому +3

      It more likely depends on your project structure, but it's not a very optimized approach since the blocs will occupy RAM whether they are needed or not.
      I myself use both approaches in my app. I have some blocs which are needed to access globally, and some will be injected where they are necessary, And this will be found out during implementation mostly.

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

      good question

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

    thanks, keep up the good work. You explain very well

  • @uzair3d
    @uzair3d 5 років тому

    Thanks a lot Paul! Have been following you since Ionic 3 times.

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

    Hi Paul , do you have some reccomended architecture of Flutter project that i can learn into ?

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

    Wow, that's amazing! Clear explanation and perfect code organization into different packages and classes. Thanks million!
    By the way, I couldn't find the article. Please update the link.

  • @animatrix1851
    @animatrix1851 5 років тому +4

    The article link points to a "Not found" webpage, does this mean you've pulled it out cause it's not up to date or something ?

  • @MrLarryQ
    @MrLarryQ 5 років тому +1

    Thanks for the video. Unfortunately however, the article link appears to be broken?

  • @mustofa_id
    @mustofa_id 5 років тому +3

    1:05 flutter create flutter_bloc && cd $_
    Underscore variable save last param of your last command.
    Btw, great explanation.
    Thank you!

    • @paulhalliday
      @paulhalliday  5 років тому +1

      Thanks Mustofa! I’ll keep that in mind for the future.

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

    A new follower successfully earned :D
    Keep it up, amazing content.

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

    awesome tutorial . May I ask, what theme are you using for VS Code?

  •  5 років тому

    Great video! Thanks! Just one question: is not necessary call 'dispose'?

  • @Corey3D
    @Corey3D 5 років тому

    I was wondering if this is a good approach for authentication as well?

  • @jonathanborralho349
    @jonathanborralho349 5 років тому

    Could you make a video about http calls using the Provider + Bloc Pattern?

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

    12:37 minutes well spent, thanks :)

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

    Great video! Noticed the link to the article was broken, would be great if you could put that back up. Cheers!

  • @0x544D
    @0x544D 4 роки тому

    Clean , on point and straight up to the code !
    Well done mate .
    +1 sub .

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

    What is the font that you are using?

  • @xalphax1121
    @xalphax1121 5 років тому +9

    As I know provider is alternative to BLoC ehy you're combining them? , but your short vid is amazing and you did good job in explaining

    • @cuberob
      @cuberob 5 років тому +3

      Yeah this is a bit confusing to me as well. The bloc pattern is all about being observable, so you only input and extract info through streams afaik. The provider removes that stream complexity by introducing the 'notifyListeners' calls. So I think the CounterBloc actually has nothing to do with the actual BloC architecture in this case. Maybe CounterViewModel or CounterProvider would be more appropriate names here? Other than that still a nice video :)

    • @oemeraran8183
      @oemeraran8183 5 років тому +4

      @@cuberob i agree, using the term bloc is confusing

    • @VladiR20
      @VladiR20 5 років тому +2

      BLoC is a design pattern, Provider is a dependency injection library. They can be used together, one is not an alternative to the other, provider makes providing and injecting the bloc easier. BLoC is just what the name says, a component that handles BL, with streams/futures/getters.

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

    What is this font, you are using ?

  • @RobertWildling
    @RobertWildling 5 років тому +1

    The link to the article results in a 404... couldn't find it on that page. Any chance for a proper link? Thank you!

  • @mousanajafi5490
    @mousanajafi5490 5 років тому +1

    the article link has broken please fix that

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

    Hi, I like the font of the code in this video , which font do you use?

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

      Hey Hao! I made a video on my font choice: ua-cam.com/video/NoPe1KXYOtg/v-deo.html

  • @oliverbytes
    @oliverbytes 5 років тому

    Is it the convention to use the Bloc word after the class name when only using the Provider package without the actualy Bloc package involved?

    • @kuldeepsharma7499
      @kuldeepsharma7499 5 років тому +1

      No

    • @oliverbytes
      @oliverbytes 5 років тому

      @@kuldeepsharma7499 I named mine instead with a Provider in the end like CounterProvider

  • @dhiraj787
    @dhiraj787 5 років тому +1

    Awesome Video , i was waiting for you to make videos on flutter.

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

    Pls what is the job market like in flutter development these days?

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

    Great explanation!

  • @miltondavilaharjula
    @miltondavilaharjula 5 років тому

    Thanks for the video. Could you create one using Provider StreamProvider?

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

    Hey! The link is broken! Is there a fix coming for it?

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

    straight forward explanation at the right speed, you just saved my neck from a client

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

    Nice walkthrough. I don't see how this has to do with BLoC

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

      Indeed, Provider and Bloc are two different things. Thats a bit confusing here.

  • @ahmeedelbaz
    @ahmeedelbaz 5 років тому

    Good job man, that was simple and useful.

  • @RohitKumar-dg2qt
    @RohitKumar-dg2qt 4 роки тому

    some say bloc is better than provider. some prefer provider.
    what you think?
    which one is better?
    easy to learn?
    easy to handle/apply?
    good for long run?

  • @belqisshida5345
    @belqisshida5345 5 років тому

    how to avoid unnecessary rebuilds? example:
    Widget A.
    Widget B.
    Widget C.
    Here when I update a state in Widget A with provider, the Widgets B and C rebuilds too.
    So how to avoid unnecessary rebuilds in B and C ?

  • @Tonbeans
    @Tonbeans 5 років тому +1

    Hi, is this what I have to do when fetching json?

    • @paulhalliday
      @paulhalliday  5 років тому +1

      Provider allows you to easily access state across multiple widgets.

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

      Read the documentation. 🤗

  • @OppaMixes
    @OppaMixes 5 років тому +3

    is this a BLoC tutorial or Provider?

  • @abhalla
    @abhalla 5 років тому +1

    Good video! What theme and font are you using? I like it.

    • @paulhalliday
      @paulhalliday  5 років тому

      Here's my dev setup: ua-cam.com/video/x7kzlz6loRo/v-deo.html

  • @AriefSetiyoNugroho
    @AriefSetiyoNugroho 5 років тому

    how if i have some routes, and i want to pass the provider to them??
    so on destination route i just call the Provider.of(context)

  • @sudhan8802
    @sudhan8802 5 років тому

    How to use one provider on multiple pages?
    I tried but showing an error to me. can u help me?

  • @andyc8707
    @andyc8707 5 років тому

    Link to article is down

  • @meme-seller1500
    @meme-seller1500 4 роки тому

    Thank u so much for this video!

  • @SmashHighlights
    @SmashHighlights 5 років тому +1

    Great explanation, thanks!

  • @creative-commons-videos
    @creative-commons-videos 5 років тому +1

    how to get initial data without onpress button, like as soon as screen loaded i want to fetch users from server, i can not add userBloc.getUsers() into initalState(), it says => inheritFromWidgetOfExactType(_Provider) or inheritFromElement() was called before _MyAppState.initState() completed.

    • @paulhalliday
      @paulhalliday  5 років тому +2

      I'll see about making a video on this.

  • @HemangJoshi
    @HemangJoshi 5 років тому

    please give code download link...

  • @yuehernkang
    @yuehernkang 5 років тому

    the link is not working

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

    @Paul Halliday Hello, GETX would be a nice package to discuss.. State simple/reactive management(without codegen), route Management and Dependencies management in an one only place.. I have been using that, and Really, this is a wonderfull tool. High productivity + Huge simplicity. Could please make some content about that? thx a lot

  • @DavidBreece
    @DavidBreece 5 років тому

    Article page is 404?

  • @sebastianhiguita933
    @sebastianhiguita933 5 років тому +1

    Awesome explanation.

  • @muhammedbarikhan3955
    @muhammedbarikhan3955 5 років тому

    How can i call increment function in initstate() to increase counter one in first run? I try to use Provider.of(context, listen: false).increment(); but show an error when call notify listeners?

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

      pub.dev/packages/provider#faq
      is your answer.

  • @MahmoudNabhanNiypoo
    @MahmoudNabhanNiypoo 5 років тому

    nice work !! Thanks for this lesson

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

    Hi Paul. Thanks for this. Its appalling that most flutter tutorials are pretty basic and old (10 months plus old!). I would love to see an example app using bloc pattern, provider or even mobx with some crud functionality over an API. Sharedpreferences and Login functionality before performing these crud would be awesome. I cant seem to find anything meaningful to guide me on this. Makes me start to wonder whether flutter is really as popular as Google claims!! Paul @paulhalliday, would you please show us something on this front? Thanks in advance...

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

    Thank you!!! Now it's Very clearly to me =)

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

    this video was great

  • @mohammedmokhtar2482
    @mohammedmokhtar2482 5 років тому

    awesome video thanks paul so much

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

    That was quite useful. Thanks!

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

    really good one

  • @MrChickenpoulet
    @MrChickenpoulet 5 років тому +1

    oh that was a nice video ! Thanks !

    • @paulhalliday
      @paulhalliday  5 років тому +1

      Thanks a lot! More Flutter videos on the way. 🙌🙌

  • @sulaimantriarjo8097
    @sulaimantriarjo8097 5 років тому +4

    I am getting more confused right now about bloc using rxdart or provider like in this video

    • @paulhalliday
      @paulhalliday  5 років тому +7

      I’m working on some examples with RxDart, still learning Flutter myself. Hoping to share as I continue to learn more.

    • @sulaimantriarjo8097
      @sulaimantriarjo8097 5 років тому +1

      @@paulhalliday that would be great. I am waiting for that

  • @Shit873
    @Shit873 5 років тому

    What theme are you using?
    Amazing Video buddy!! I watched a number of tutorials on provider before coming to this one, and this is by far the best!

  • @TaweechaiMaklay
    @TaweechaiMaklay 5 років тому

    Really clean, thank you

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

    finally tutorial i can understand

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

    Thank you!

  • @vic1918
    @vic1918 5 років тому

    Amazing e easy video thanks!

  • @SreekumarMenonPhotography
    @SreekumarMenonPhotography 5 років тому +2

    In every tech video, there is always one person who ask this question- "what is the vs code (*replace with other editors) theme that you are using ?" :)

    • @angelhdzdev
      @angelhdzdev 5 років тому +1

      And how that offends or hurt you?

  • @g-luu
    @g-luu 5 років тому

    i got confused to how was setter called inside the inc and dec functions

    • @paulhalliday
      @paulhalliday  5 років тому +1

      As we changed to from modifying _counter and manually calling notifyListeners to instead using counter (the setter), notifyListeners was called from within the setter itself.

    • @g-luu
      @g-luu 5 років тому

      I see.... i guess I was expecting to see set counter being used like this for instance -> counter(number); If that makes sense.

    • @JonasDeVrient
      @JonasDeVrient 5 років тому +1

      @@g-luu Yes, like in Java, but it in Dart we use it directly because of the 'set' keyword in front of counter.

    • @g-luu
      @g-luu 5 років тому

      @@JonasDeVrient oh oh oh i see i guess it went over my head cause i did not see "this.counter" . Thanks for clarifying that. I think i will try flutter out. Hopefully Paul gets on top of it with a Udemy course soon.

  • @hoseinquest
    @hoseinquest 5 років тому

    thank you so much

  • @AndreasFelix
    @AndreasFelix 5 років тому

    Great video thank you for sharing.

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

    tnx for this!

  • @ArshdeepSingh-ob7rj
    @ArshdeepSingh-ob7rj 3 роки тому +1

    Why to use the word bloc when there is no bloc ,It's just provider. And Bloc arc is my worst nightmare. Provider is the best and the most understandable, BTW Great video

  • @mattfrowe7697
    @mattfrowe7697 5 років тому

    What's with the icon / foreground on that fab?? :)
    P.S great video, thanks

    • @paulhalliday
      @paulhalliday  5 років тому +1

      That would most likely be my channel's profile image and is an overlay on UA-cam? :P

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

    I'm confused. Is this tutorial saying BLOC and Provider are the the same thing?
    I thought BLOC and Provider were two different state management techniques.

  • @techzone-lk-zone3075
    @techzone-lk-zone3075 5 років тому +1

    good one

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

    Why are you using the term "bloc" here??

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

    Really nice video man! I'm starting this flutter path and this video helped me a lot! and just in case someone is thinking about optimizations for their widget tree i would recommend to check their docs related to state managment: flutter.dev/docs/development/data-and-backend/state-mgmt/simple keep it up!

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

    This is more like mvvm rather than bloc pattern.

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

      Yes it is like the mvvm, Well you should check this video too over provider!ua-cam.com/video/hRStAmkTcJY/v-deo.html

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

      @@Abhishvek thanks, there is awesome tutorial on bloc patterns and mvvm... Provider is handy for small apps, but when it comes to more complex things it makes a mess. 😇

  • @89stoev
    @89stoev 5 років тому +3

    Hey friend, Provider is a sort of HOC with a centralized state thats being provided to all consuming widgets. BLOC is a whole different thing thats all about Reactive Programming and Observables , in dart case - Streams. Sorry to say but with this video and the article , you are making confusion among the community. To clear things more, there are few state managments in flutter. Bloc(Reactive programming), Provider(HOC) & Scoped_Model(HOC) and Redux.

    • @mohamedzayani7819
      @mohamedzayani7819 5 років тому

      Agree, just about to post a comment about the same. The video is great but it is not about the Bloc pattern. provider is mostly syntax sugar for InheritedWidget (as per provider page in pub.dev)

  • @alpitanand20
    @alpitanand20 5 років тому

    Use this ChangeNotifierProvider.value(
    value:CounterBloc()
    )
    Instead of this
    ChangeNotifierProvider.value(
    notifier:CounterBloc()
    )
    The Provider have been updated.

  • @ddean3732
    @ddean3732 5 років тому

    Getting 404 at the website article

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

    If this would have been a react native tutorial it would have ended at 1:11

  • @TheEndlessSea
    @TheEndlessSea 5 років тому

    If only your website had a search...

  • @amrinjaffni4268
    @amrinjaffni4268 5 років тому

    So it's basically just another class made specifically to store the function 🤔 something like that I guess

  • @mohamedgaber5533
    @mohamedgaber5533 5 років тому

    street to point it's an amazing content ma friend ,, keep learning and uploading video

  • @lock-account
    @lock-account 4 роки тому

    Eureca!

  • @julianarnold7992
    @julianarnold7992 5 років тому +2

    Bloc and Provider are different state mangement tools. You're mixing things up.

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

    tq ew
    ............

  • @flutterwithvitul
    @flutterwithvitul 5 років тому

    🌹🌹