Fireship · @fireship

Flutter State Management - The Grand Tour

Uploaded March 12, 2019 · Length 14:07

Flutter State Management - The Grand Tour

Summary

Flutter State Management - The Grand Tour: 10 ways to build a basic counter app using different state management strategies in Flutter.

  • flutter state management
  • flutter state management strategies
  • flutter counter app
  • flutter stateful widget
  • flutter stateless widget
  • flutter inherited widget
  • flutter behavior subject
  • flutter rx dart

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:06

    state management for whatever reason is

  3. 0:09

    a topic that brings out strong opinions

  4. 0:10

    and developers I'm gonna have to go

  5. 0:17

    ahead and sort of disagree with you

  6. 0:18

    there in today's video we'll look at 10

  7. 0:20

    different ways to build a basic counter

  8. 0:22

    app using different state management

  9. 0:23

    strategies employer we'll also just talk

  10. 0:25

    about what state management is and why

  11. 0:27

    there are so many different ways to

  12. 0:28

    approach it and hopefully by the end of

  13. 0:29

    this video you know exactly where

  14. 0:31

    strategy is ideal for your app if you're

  15. 0:33

    new here like and subscribe and you grab

  16. 0:34

    the full source code on fire ship IO and

  17. 0:36

    I'm giving away another t-shirt with

  18. 0:38

    this video just leave me a comment with

  19. 0:39

    your own opinions about state management

  20. 0:41

    below first of all what is stake in a

  21. 0:43

    reactive framework like flutter you can

  22. 0:45

    think of your UI as the return value of

  23. 0:47

    a function that function gets called

  24. 0:48

    with one argument which is your state so

  25. 0:51

    state is just data that changes over the

  26. 0:53

    lifecycle of your app a lot of your data

  27. 0:55

    can be self-contained within a single

  28. 0:56

    widget that's known as local state we'll

  29. 0:59

    look at the tools that we have built

  30. 1:00

    into flutter to manage local state which

  31. 1:01

    is pretty straightforward things get

  32. 1:03

    interesting when we start talking about

  33. 1:04

    global state or state that needs to be

  34. 1:06

    shared throughout the widget tree coming

  35. 1:08

    from the web development world I've seen

  36. 1:09

    tons of debate over state management and

  37. 1:11

    a lot of apps over engineered with these

  38. 1:13

    big state management libraries that

  39. 1:15

    didn't really need them that's not to

  40. 1:16

    say they're not valuable but even the

  41. 1:18

    creators and maintainer of those

  42. 1:19

    libraries will tell you that you

  43. 1:20

    probably don't need them we'll talk

  44. 1:22

    about the pros and cons of these various

  45. 1:23

    libraries as we go but for now let's

  46. 1:25

    focus on the fundamental building blocks

  47. 1:27

    in flutter starting with the stateful

  48. 1:29

    widget when you run flutter create from

  49. 1:30

    the command line it gives you some

  50. 1:32

    starter code that increments a counter

  51. 1:33

    with a stateful widget we're going to

  52. 1:35

    rebuild this counter multiple times

  53. 1:37

    throughout this video using different

  54. 1:38

    state management strategies to create a

  55. 1:40

    stateful widget we need two classes the

  56. 1:42

    first one is the stateful widget itself

  57. 1:44

    and that implements a create state

  58. 1:46

    method and that returns our second class

  59. 1:48

    which is an extension of the state class

  60. 1:50

    and this is where all the heavy lifting

  61. 1:52

    happens first we define a property

  62. 1:54

    called counter which is an integer that

  63. 1:56

    defines the actual data state of this

  64. 1:57

    widget then we define a method called

  65. 1:59

    increment counter and it calls a method