📱 Flutter
Beginner
What is initState() in Flutter?
Answer
initState() is called exactly once when the State object is first inserted into the widget tree, before the first call to build(). It is the right place to initialize controllers, subscribe to streams, and trigger one-time data fetching. Always call super.initState() first. You cannot use BuildContext for things like navigation or showing dialogs directly in initState() — instead, use WidgetsBinding.instance.addPostFrameCallback() to run code after the first frame.