Search⌘ K

Stateless Widgets

Explore the concept of stateless widgets in Flutter and understand why they cannot re-render UI when internal state changes. Learn how the build() method works and see examples illustrating the difference between stateless and stateful widgets, helping you manage Flutter UI updates effectively.

Stateless and stateful widgets comparison

In Flutter, we can create either a stateless widget or a stateful widget. Strictly speaking, when a widget interacts with users, it’s a stateful widget.

The opposite is also true. A stateless widget never changes and cannot be interacted with by users.

However, the concept of state in Flutter is not as straightforward as it appears in the above statement.

In this introductory chapter, we will try to understand the finepoints of state in Flutter.

The stateful widget has an internal state that is absent in the stateless widget. As we see in both cases, the UI is re-rendered when the input data changes. However, the UI is re-rendered in the stateful widget when the internal state or local data changes.

The following diagram ...