What is the difference between StatelessWidget and StatefulWidget?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Flutter development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

A StatelessWidget has no mutable state — it renders based solely on the constructor arguments passed to it and never changes after being built. It is ideal for static UI elements like labels or icons. A StatefulWidget maintains a separate State object that can change over time in response to user interactions or data updates, triggering a UI rebuild. When state changes, you call setState() inside the State object to notify Flutter to rebuild the widget.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Flutter codebase.