Problem Statement
What is the purpose of initState() in a StatefulWidget?
Explanation
InitState() is called exactly once when the State object is created, making it perfect for one-time initialization like creating controllers, initializing state variables, setting up subscriptions, or starting animations. It's guaranteed to be called before the first build() call, so you can safely initialize data that build() depends on.
You must call super.initState() at the beginning of your override to ensure proper initialization of the parent State class. InitState() doesn't have access to BuildContext-dependent data yet - use didChangeDependencies() if you need to access InheritedWidgets or theme data during initialization.
Common uses include creating TextEditingController, AnimationController, subscribing to streams, initializing state variables from constructor parameters, and setting up listeners. Never call setState() inside initState() as the widget isn't built yet - just assign values directly to state variables.
