For more information, see:

StatefulWidget

setState()

Bringing it all together

What follows is a more complete example that brings together
these concepts: A hypothetical shopping application displays various
products offered for sale, and maintains a shopping cart for
intended purchases. Start by defining the presentation class,
ShoppingListItem:

The ShoppingListItem widget follows a common pattern
for stateless widgets.  It stores the values it receives
in its constructor in final member variables,
which it then uses during its build() function.
For example, the inCart boolean toggles between two visual
appearances: one that uses the primary color from the current
theme, and another that uses gray.