Learn Flutter Hooks and Maximize Your Code Reuse

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • Flutter Hooks is a package that lets you separate the life-cycle logic from widgets to its own classes and methods. It's very powerful and now we will learn how to utilize it!
    Course to build a production-ready app 👉 robertbrunhage.com/course
    00:00 Overview
    01:41 StatefulWidget
    03:26 HookWidget with useEffect
    05:22 Create custom hook
    Source code: github.com/RobertBrunhage/flu...
    ····················································································
    ♥ Become a Patreon supporter: / robertbrunhage
    ♥ Subscribe: bit.ly/2SUyRhx
    ····················································································
    ● Website: robertbrunhage.com
    ● Twitter: / robertbrunhage
    ● Discord: / discord
    ● Instagram: / robertbrunhagedev
    ● Facebook: bit.ly/RobertDev

Komentáře • 95

  • @martinalcala4823
    @martinalcala4823 Před 3 lety +23

    As a React developer, this was sooo beautiful!

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

    Amazing 👏 Love that so much, very similar to react hooks which I am a very huge fan of 😍😍

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

    Sound Great. I love it.

  • @rcjuancarlosuwu
    @rcjuancarlosuwu Před 2 lety

    Good job! It was really clear to understand. thanks!

  • @youtornado
    @youtornado Před 3 lety +56

    My first action: Installing the Remove Comments Extension 😂

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

    great tutorial 👍

  • @DoctorCode9
    @DoctorCode9 Před 3 lety +10

    I never heard about Flutter Hooks before this video, Thanks man ❤

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

    Heard the Hook before, but never know how use it until now. 😀 Great tutorial, and keep it up 😍

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

    So nice content :) I think one important principle is that everything in flutter is a widget, so in this case I would create a widget for the timer and reutilize/customize it across the app instead of reutilizing the functionality. But anyway is so great to count with that library for some special scenario

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

    just found in CZcams recommendations ... I really liked it considering I am new to flutter in general! Thanks. Btw nice explanation not too long or too short

  • @dev_casper
    @dev_casper Před 2 lety

    Great explanation.

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

    Great Video👍!
    Good Explanation.
    Want More Videos like this !

  • @rishabhgupta0.8
    @rishabhgupta0.8 Před 2 lety

    explained very well.

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

    Good presentation. Keep this up! - I felt like I'm watching Fireship. :)

  • @thkp-eng
    @thkp-eng Před 3 lety

    Very cool! Always wondered if hooks could be applied to Flutter given it's conceptual similarity to React!

  • @DavidSmith-ef4eh
    @DavidSmith-ef4eh Před 3 lety +14

    Great stuff, almost exactly like in React. The only problem I have with it, I rarely share code between widgets. But I'll keep that library in mind for future scenarios.

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

      Thank you
      I really like it as it has predefined hooks for things like state, animation etc which makes it a lot easier to implement in general!

    • @whyimustusemyrealname3801
      @whyimustusemyrealname3801 Před 3 lety

      yeah same here even though I appreciate it that remi push this into main repo, until this moment I never think that I need hook in flutter, in react though I really loves hook and always use hook whenever I can

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

    I like your content.

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

    Flutter Hooks are much easier to understand and reason about and also they're just like react hooks so that's a plus

  • @anggapande8395
    @anggapande8395 Před 3 lety

    hay, can you give a tutorial to create customize cluster in map. i already try with plugin but it not bocome what i want and the clustering is not smooth.

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

    Excellent Tutorial, Looking forward to an animation video

  • @sujalabhani980
    @sujalabhani980 Před rokem

    Thanks for the great actual use case tutorial, but i have a question what is if i wanna know the value outside the build method? what if i wanna pass to x function without listening to? maybe i will take look at hooks package

  • @adamgonzales8677
    @adamgonzales8677 Před 2 lety

    Reactjs developers are loving this feature I'm sure of it

  • @grAPPfruitMacroCraft
    @grAPPfruitMacroCraft Před 3 lety

    Is it not possible to do the same thing with mixins?

  • @veeresh4441
    @veeresh4441 Před 3 lety

    Can't we use state management (like redux bloc or provider) for this purpose.

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

    Amazing video, great job 👍🏽 Just to be sure, the context parameter in your useInfiniteTimer function is useless here, am I wrong?

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

      Oh yeah, that is a miss. The context is not needed!
      I commited a change on GitHub

  • @farhadentezari6206
    @farhadentezari6206 Před 3 lety

    Very well explained thanks! I dont get dispose() - what happens if you forget to dispose?

    • @unknownunicorn1373
      @unknownunicorn1373 Před 2 lety

      You'll end up w/ a memory leak and/or unnecessary cpu usage if you create a lot of timers and leave them running in the background

  • @hadirahmani7943
    @hadirahmani7943 Před rokem

    thanks, so what was the result?

  • @beijunxi4697
    @beijunxi4697 Před 3 lety

    aaaaaaamazing

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

    (8:11) useInfiniteTimer method is having a parameter BuildContext, but is it necessary ? Because it is not used by the method 🤔

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

      It was a mistake and fixed if you check the GitHub repo in the description!

  • @JohnDoe-fv5cu
    @JohnDoe-fv5cu Před 3 lety +4

    The same stuff can be implemented using mixins, without any third party libraries

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

      Yes but there are other drawbacks with that: github.com/flutter/flutter/issues/51752

    • @EduardoLima-pi7fl
      @EduardoLima-pi7fl Před 3 lety +1

      Hi John, I'm starting with Flutter and I was curious how this can be implement using mixins, could you share an example? Tnks

  • @SirJagerYT
    @SirJagerYT Před 2 lety

    i dont understand why we need to pass context inside useInfiniteTimer(context); Why ?

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

    I am new to state management. Could anybody explain the difference between hooks, getx, provider, and riverpod? Or are they used for the same thing but with different implementations? Thanks!

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

      hooks isn't really a state management solution - its a way to separate reusable _logic_ from your widgets
      the others _are_ state management libraries, however, note that getx is a highly controversial package as it does things in a way many people dislike, plus i think there was some drama about it at some point.
      riverpod is said to be a rewrite of provider.

    • @marflage
      @marflage Před 2 lety

      @@TekExplorer thanks for the reply. But isn't state management accomplished through separation of concerns?
      Yeah, I have heard about the whole drama about getx's author claiming his package was the best.

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

      @@marflage I don't think that's technically necessary for a state management solution to be a state manager.
      Regular ol statefulwidget is a state management solution, after all (though not a good one for anything outside the widget on its own)

    • @marflage
      @marflage Před 2 lety

      @@TekExplorer I see, thanks

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

    It's so similar to react hooks :)

  • @Balqini
    @Balqini Před 3 lety

    What is the extension that you use in the 1:31 ? I'm new to flutter.

  • @shlokbhakta2893
    @shlokbhakta2893 Před rokem

    Man woke up and chose violence with the comments

  • @f-person
    @f-person Před 3 lety +1

    Why did you need context argument for useInfiniteTimer?

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

      Nope I have updated the code in GitHub! See the link in the description, was a mistake and didn't notice it haha

    • @f-person
      @f-person Před 3 lety

      Okay. Thanks for the video!

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

    Great learning content! Btw which ide is that?

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

      I am using VSCode!

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

      @@RobertBrunhageHow did you get that background color in vscode? It looks so stunning and beautiful!

    • @RobertBrunhage
      @RobertBrunhage  Před 3 lety

      @@soumikpaul7960 hmm maybe it's my theme, I don't really know haha.
      I am using One Dark Pro. Give it a go and see if it's what you are after!

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

      @@RobertBrunhage Thanks a lot loved your content!

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

    Can you please make a video on how to use moor in flutter web , thank u for all the good videos

  • @syleishere
    @syleishere Před 3 lety

    He seriously needs to learn getX. He doesn't even need to use stateful widgets anymore, this is so old school

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

    Just write stl instead of stle and stf for statefullwidget

  • @jasonsebring3983
    @jasonsebring3983 Před 3 lety

    way cleaner, smaller code, good stuff. ... now how to do this with global state, streams etc...

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

    Can you help me for How to start freelancing as a flutter developer...

    • @RobertBrunhage
      @RobertBrunhage  Před 3 lety

      I would if I was someone that had been doing freelancing, sadly I have not :(

    • @tarunverma8693
      @tarunverma8693 Před 3 lety

      @@RobertBrunhagebut how flutter developer make passive income.

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

      Freelancing is not about passive income - it is more about improving your Flutter skills, applying for projects, and doing actual work...

    • @rumble1925
      @rumble1925 Před 3 lety

      @@tarunverma8693 you get passive income from having people work for you or make a product to sell. Freelancing means selling your own time, which is not passive.

  • @nt4f04und
    @nt4f04und Před 3 lety +8

    horrible anti-pattern for flutter as per me and the flutter team itself, if you follow up the github.com/flutter/flutter/issues/25280
    what the heck do hooks give you you can’t achieve with flutter state management toolings. remember the hooks will definitely have some performance drawback

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

      Same thing I was wondering, so many drawbacks, no clear advantage that could only be accomplished by the use of hooks or at least largely advantegeous

    • @hawkybae
      @hawkybae Před 3 lety

      Definitely a good idea not choosing to add hooks to the core Flutter framework. Also making a core architectural change because it 'works' on another framework is absurd.
      Nevertheless, it's good having the option to use hooks as a separate package.

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

      I would not say it's a anti-pattern and nothing that the Flutter team has said either (to my knowledge). I recommend this post github.com/flutter/flutter/issues/51752 for more indepth information.

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

      what i think about this whole thing github.com/flutter/flutter/issues/51752#issuecomment-723564582

  • @ankitrathore3946
    @ankitrathore3946 Před 3 lety

    Why are you making flutter looks like react ??

    • @waiyanphyo7
      @waiyanphyo7 Před 3 lety

      totally agree no longer flutter style -_-

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

    first

  • @SAMSHELDINTHOMAS
    @SAMSHELDINTHOMAS Před 3 lety

    Hi Can i use fluttur hook in this project,,,
    github.com/samsheldin/checkout
    hi there is a json of a shopping cart app
    in each object of the list there is a discount start and discount end
    so i know know how to make the price change based on the timing for individual products,,,
    but logic looks a bit confusing when i am totalling the price and displaying it in ui,,,
    for eg 10 + 5(discounted price) + 10 + 5(discounted price) + 5(discounted price)
    total price 35
    now suppose after 5 min user is still on the screen discount on one of the products end
    it looks like this
    10 + 10 + 10 + 5(discounted price) + 5(discounted price)
    total price 40..
    So dislpaying the discount individally is alright,,, but as you can see how can i do the total price based on differnt discount start time and discount end time for each unique product
    this is the ui which i am implementing this ,,, so is it possible to use flutter hooks here

  • @blackhatvisions
    @blackhatvisions Před 3 lety

    Repeating the regular code 7 times is easier than implementing the hook.

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

      Unless you had a bug... then you just copied it 7 times across your app. Or if something has to change, you now have 7 maintenance points.

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

    Not a fan of useEffects. So much extra messy code with anonymous functions within another function. Less readable than separating code into different functions

  • @elvincitore1512
    @elvincitore1512 Před 3 lety

    talk about a complete rip off of react hooks