Zum Inhalt

Interaction and Behaviour

Key Points

  • The capability of UI elements to react to user input is called interaction or interactivity.
  • The way a widget reacts either to user intput or an internal state change is called behaviour.
  • A widget’s behaviour is implemented in the form of logical control statements.
  • A widget reacts to user input by implementing handlers that capture the events (issued by the user or externally – e.g. when a remote operation finishes) for which they were defined.
  • A TextEditingController allows to read content from a text field.
  • Implementing interactivity requires stateful widgets.
  • A stateful widget is implemented by two classes: a subclass of StatefulWidget and a subclass of State.
  • A widget’s state is stored in a State object, separating the widget’s state from its appearance.
  • The state consists of values that can change, like a slider’s current value or whether a checkbox is checked.
  • When the widget’s state changes, the state object calls setState(), telling the framework to redraw the widget.
  • The state class contains the widget’s mutable state and the widget’s build() method.

Where do you find relevant information

Excercises for deeping the knowledge

Create a single-page Flutter app that randomly changes the background color of the Scaffold every time the user tabs on a centrally placed button.

Bugfixing Information