What is initState() in Flutter?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Flutter basics — a prerequisite for any developer role.
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.
Common Mistake
Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Flutter project.