The following state class, _MyStatefulWidgetState,
implements the build() method for the widget.
When the state changes, for example, when the user toggles
the button, setState() is called with the new toggle value.
This causes the framework to rebuild this widget in the UI.

What are the StatefulWidget and StatelessWidget best practices?

Here are a few things to consider when designing your widget.

Determine whether a widget should be
a StatefulWidget or a StatelessWidget.

In Flutter, widgets are either Stateful or Stateless—depending on whether
they depend on a state change.

If a widget changes—the user interacts with it or
a data feed interrupts the UI, then it’s Stateful.

If a widget is final or immutable, then it’s Stateless.

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