author avatar

sujay

Wed Dec 20 2023

In Flutter, widgets are the building blocks of your UI (similar to components in React), and there are mainly 3 type of widgets based on how they handle state: Stateless, Stateful, and Inherited widgets

Stateless Widgets: - Stateless widgets are immutable i.e. their configuration cannot change once they are created. They represent parts of your UI that don't depend on any mutable state. - Stateless widgets rebuild when their parent widget or the widget hierarchy above them rebuilds and when an Inherited widget it depends on changes

Stateful Widgets: - Stateful widgets are mutable and holds some internal state that can change over time. They are used when a part of your UI depends on dynamic data or user interactions. - Stateful widgets rebuild when their internal state changes. State updates are handled using setState() which also triggers a rebuild of the widget and its subtree. They can also rebuild when their parent widget or the widget hierarchy above them rebuilds.

Inherited Widgets: - Inherited widgets are a special type of widget used to share data or state across an entire widget subtree without having to pass the data explicitly to every widget in the subtree (concept of Inherited widget is similar to Context API in React) - Whenever the value inside Inherited widget changes, the widgets dependent on this widget get rebuilt.