Problem Statement
What is the correct order of lifecycle methods when a StatefulWidget is first created?
Explanation
When a StatefulWidget is first inserted into the widget tree, Flutter calls createState() to create the State object, then immediately calls initState() on that State object for one-time initialization. After initState(), didChangeDependencies() is called automatically because the State object's dependencies are established for the first time.
Finally, build() is called to create the widget tree. This sequence ensures the State object is properly initialized before the widget is built. InitState() runs only once during the widget's lifetime, while build() can be called multiple times whenever the widget needs to rebuild.
Understanding this order is crucial for proper initialization - for example, you can't call BuildContext-dependent methods like Theme.of(context) in initState() because the dependencies aren't fully set up yet. Use didChangeDependencies() for initialization that depends on InheritedWidgets or other context-dependent data.
