Flutter & Dart (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the complete lifecycle of a `StatefulWidget`?
junior LevelCode ExampleLifecycle
In Simple Words:
The State object transitions through these methods in order:
createState(): Called by Flutter to instantiate the state object.initState(): Called exactly once when the widget enters the tree. Used to initialize controllers, subscribe to streams, and setup animations.didChangeDependencies(): Called immediately afterinitState()and whenever anInheritedWidgetit depends on changes.build(): Called repeatedly wheneversetState()is called or dependencies update; returns the widget subtree.didUpdateWidget(oldWidget): Called when parent widget re-evaluates and passes new configuration props.deactivate(): Called when widget is temporarily removed from the tree.dispose(): Permanent teardown; unregister listeners, close streams, dispose controllers (AnimationController,TextEditingController) to prevent memory leaks.
text
StatefulWidget Lifecycle:
[createState] ──► [initState] ──► [didChangeDependencies] ──► [build] ◄──┐
│ │ (setState)
[dispose] ────┘