DEV Community

Cover image for Understanding Stateless and Stateful Widgets
Atuoha Anthony
Atuoha Anthony

Posted on

Understanding Stateless and Stateful Widgets

There is really nothing much difference between a stateful and a stateless widget other than the ability to change when a user interacts a component in the screen.
Stateless widgets are widgets that does not require mutable state. It describes part of the user interface by building a constellation of other widgets that describe the user interface more concretely.

   Icon(
      Icons.beach_access,
      color: Colors.blue,
      size: 36.0,
    )
Enter fullscreen mode Exit fullscreen mode

A Stateful Widgets are dynamic widgets. They can be updated during runtime based on user action or data change. They have an internal state and can re-render if the input data changes or if Widget's state changes.

   Checkbox(
      value: this.value,
      onChanged: (bool value) {
        setState(() {
          this.value = value;
        });
      },
   )
Enter fullscreen mode Exit fullscreen mode

Differences Between Stateless and Stateful Widget
Stateless Widget:
Stateless Widgets are static widgets.
They do not depend on any data change or any behavior change.
Stateless Widgets do not have a state, they will be rendered once and will not update themselves, but will only be updated when external data changes.
For Example: Container, Text, etc are Stateless Widgets.

Stateful Widget:
Stateful Widgets are dynamic widgets.
They can be updated during runtime based on user action or data change.
Stateful Widgets have an internal state and can re-render if the input data changes or if Widget’s state changes.
For Example: Checkbox, Radio Button, etc are Stateful Widgets
Get started:
https://docs.flutter.dev/get-started/codelab

Anticipate for more future posts like converting a prototype to a Flutter App

Image description

Image description
Image description

Twitter: https://twitter.com/AtuohaA
LinkedIn: https://www.linkedin.com/in/atuoha-anthony
Github: https://github.com/Atuoha

Top comments (0)