tezvyn:

Flutter's setState(): Triggering UI Updates

Source: api.flutter.devintermediate

setState() tells Flutter "my data changed, so rebuild the UI." It's not the change itself, but the notification that a change happened. Use it in a StatefulWidget's State class when events modify data your build() method uses.

setState() is the core mechanism for triggering UI updates in a StatefulWidget. Think of it as a broadcast: "My internal data has changed, so please schedule a rebuild to reflect it on screen." You call it when an event, like a button press, alters a variable that your build() method uses. The framework then re-runs build() to update the view. The footgun: putting heavy computation or async calls inside the setState callback. The callback must be synchronous and only contain the direct state mutation.

Read the original → api.flutter.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Flutter's setState(): Triggering UI Updates · Tezvyn