concept State in category flutter

appears as: State
Flutter in Action

This is an excerpt from Manning's book Flutter in Action.

A StatefulWidget in the shopping cart application, on the other hand, is the QuantityCounter widget, because it’s managing a piece of stateful data that tracks the number of items you wish to add to your cart. A StatefulWidget object has an associated State object. The State object has special methods such as setState that tell Flutter when it needs to think about repainting.

State objects are long-lived. They can tell Flutter to repaint, but it can also be told to repaint because the associated stateful widget has been updated by outside forces.[4]

Figure 1.9. The stateful widget is actually two objects: the widget and a State object.
  • Flutter provides state management tools, such as widget life-cycle methods and special State objects.
  • class MyHomePage extends StatefulWidget {                 #1
      @override                                               #2
      _MyHomePageState createState() => _MyHomePageState();   #3
    }
    
    class _MyHomePageState extends State<MyHomePage> {        #4
      @override
      Widget build(BuildContext context) {                    #5
        // ..
      }
    }