StatefulWidgets are made up of two classes: the widget and the state. The widget part of StatefulWidget really doesn't do much, and all the properties that you store in it must be final; otherwise, you will get a compile error.
All widgets, whether they are stateless or stateful, are still immutable. In Stateful widgets, the state can change.
What doesn't have to be immutable is the State object. The State object takes over the build responsibilities from the widget. States can also be marked as dirty, which is what will cause them to repaint on the next frame. Take a close look at this line:
setState(() {
++seconds;
});
The setState function tells Flutter that a widget needs to be repainted. In this specific example, we are incrementing the seconds property by one, which means that when the build function is called again, it will replace the Text widget with different content.
Each time you call setState...