Flutter's build(): Why It Lives on State, Not the Widget
Flutter's build() method turns state into UI. It's on the State object, not the StatefulWidget, to ensure it always paints with the latest data. The framework calls it on init, after setState(), or when dependencies change.
Flutter's build() method is your widget's blueprint, turning state into UI. It's intentionally on the State class, not StatefulWidget, to solve a critical bug with outdated data. The framework calls build() frequently—on init, after setState(), or when dependencies change—so it must be fast and pure. The footgun: if build() were on the widget, closures could capture stale properties. Because it's on the persistent State object, closures can safely access the current widget's properties via `widget.propertyName`, avoiding UI bugs.
Read the original → api.flutter.dev
- #flutter
- #dart
- #state management
- #widgets
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.