Explain the internal mechanism of `setState` (marking elements dirty).
Updated Apr 28, 2026
Short answer
setState is simply a framework trigger that marks the current Element as 'dirty' and schedules it for a rebuild.
Deep explanation
Internally, setState(fn) executes your provided function, then calls element.markNeedsBuild(). This adds the Element to a global _dirtyElements list. During the next frame pipeline (driven by the Engine's Vsync signal), the framework iterates through dirty elements, calling build() to generate new widget configurations, and reconciling the tree.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro