Skip to main content
InterviewHubPRO
Section Overview
Q4

Question 4 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

8%
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:

  1. createState(): Called by Flutter to instantiate the state object.
  2. initState(): Called exactly once when the widget enters the tree. Used to initialize controllers, subscribe to streams, and setup animations.
  3. didChangeDependencies(): Called immediately after initState() and whenever an InheritedWidget it depends on changes.
  4. build(): Called repeatedly whenever setState() is called or dependencies update; returns the widget subtree.
  5. didUpdateWidget(oldWidget): Called when parent widget re-evaluates and passes new configuration props.
  6. deactivate(): Called when widget is temporarily removed from the tree.
  7. dispose(): Permanent teardown; unregister listeners, close streams, dispose controllers (AnimationController, TextEditingController) to prevent memory leaks.
text
StatefulWidget Lifecycle:
[createState] ──► [initState] ──► [didChangeDependencies] ──► [build] ◄──┐
                                                                 │        │ (setState)
                                                            [dispose] ────┘