The setState() Method

Stateful widgets

Widgets in Flutter describe how the UI should look depending on the configuration and state. We categorize widgets into two:

  • Stateless widgets: They only depend on the configurations set and do not change on user interaction.
  • Stateful widgets: They depend on the configurations set and the app’s state and change on user interactions.

Stateful widgets extend the State class, where we can call the build method several times to rebuild the UI. The code snippet below shows the structure of a stateful widget.

Get hands-on with 1400+ tech skills courses.