What is setState() in Flutter?
Why Interviewers Ask This
This is a classic screening question for Flutter roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
setState() is a method on the State class of a StatefulWidget that notifies the Flutter framework that the internal state has changed and the widget needs to be rebuilt. You pass a callback to setState() that contains the actual state mutation. Flutter schedules a rebuild, calling build() again to generate an updated widget tree. Calling setState() outside of an active State (e.g., after dispose) will throw an error, so always check mounted if the widget might have been removed.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Flutter candidates.
Previous
What is the GridView widget and how does it differ from ListView?
Next
What is the SizedBox widget?