Determine which object manages the widget’s state (for a StatefulWidget).

In Flutter, there are three primary ways to manage state:

The widget manages its own state

The parent widget manages the widget’s state

A mix-and-match approach

When deciding which approach to use, consider the following principles:

If the state in question is user data,
for example the checked or unchecked mode of a checkbox,
or the position of a slider, then the state is best managed
by the parent widget.

If the state in question is aesthetic, for example an animation,
then the widget itself best manages the state.

When in doubt, let the parent widget manage the child widget’s state.

Subclass StatefulWidget and State.

Add the StatefulWidget into the widget tree.

Add your custom StatefulWidget to the widget tree
in the app’s build method.