Back to Writing
NOTESflutterlifecyclestateful-widgetdartmobile-dev
Flutter - 07. Stateful Widget Lifecycle
March 22, 2020•Updated Feb 17, 2026
Understanding the lifecycle of Flutter Stateful widgets:
createState
- Called once when the widget is first created.
- Returns a State instance.
initState
- Called once immediately after the State is created.
- Used for variable initialization and subscribing to event streams.
build
- Called every time the widget needs to be rebuilt.
- Returns the widget's UI.
setState
- Called to notify the framework of state changes.
- Triggers a rebuild (the build method is called again).
didUpdateWidget
- Called when the widget configuration changes.
- Useful for reacting to changes from the parent widget.
deactivate
- Called when the widget is removed from the tree.
- Used for cleanup (unsubscribing from event streams).
dispose
- Called when the widget is permanently removed.
- Final cleanup — releasing resources.
Lifecycle example:
- createState -> initState -> build -> setState -> build -> deactivate -> dispose