Difference between Stateless and Stateful Widgets.

PremKumarRai
Flutter Community
Published in
2 min readMay 15, 2022

A state is an object’s data or information that can be read synchronously when the widget is created and can change over time. We can also say anything that is stored in the app’s storage during operation is called a state.

Stateless widgets are those whose states can’t be altered or properties can’t be altered once built. When we create stateless widgets then these widgets are immutable. Any changes to the variables, icons, buttons, or obtaining data will not modify the state of the app. It is used when the UI is dependent on the information contained within the object itself. It doesn’t require a mutable state. Some examples of stateless widgets are text, icons, raised buttons, etc.

Stateless Widgets

Stateful widgets are those whose states can be altered or whose properties can be altered after they have been created. It is changeable and alters several times during its existence. Stateful widgets will store states which are useful when parts of the UI need to change dynamically. It has a mutable state. Some examples of stateful widgets are Text Fields, Checkbox, Radio buttons, etc.

Stateful Widget

Differences Between Stateless and Stateful Widget:

Stateless Widget:

  1. A stateless widget can’t change its state during the runtime of a flutter application.

2. It is a static widget.

3. Only updates when it is initialized.

4. Cant update during the runtime unless an external event occurs.

5. Doesn’t have a setState(). It will be rendered once and will not update itself.

Eg: Text, Icons, Raised Buttons, etc.

Stateful Widget:

  1. A stateful widget is used when some UI parts must change dynamically during runtime.
  2. It is a dynamic widget.
  3. It can change or update dynamically.
  4. Can update during run time based on user action or data changes.
  5. It has an internal setState() and can re-render if the input data changes.

Eg: Checkboxes, Radio buttons, etc.

--

--