The State class has a life cycle. Unlike StatelessWidget, which is nothing more than a build method, StatefulWidgets have a few different life cycle methods that are called in a specific order. In this recipe, you used initState and dispose, but the full list of life cycle methods, in order, is as follows:
- initState
- didChangeDependencies
- didUpdateWidget
- build (required)
- reassemble
- deactivate
- dispose
The methods in bold are the most frequently used life cycle methods. While you could override all of them, you will mostly use the methods in bold. Let's briefly discuss these methods and their purpose:
- initState:
This method is used to initialize any non-final value in your state class. You can think of it as performing a job similar to a constructor. In our example, we used initState to kick off a Timer that fires once a second. This method is called before the widget is added to the tree, so you do not have any...