Flutter

Widget Lifecycle

StatefulWidget lifecycle, initState, setState, dispose, didUpdateWidget, build optimization

20 preguntas de entrevista·
Junior
1

Which method is called first when creating a StatefulWidget?

Respuesta

The createState() method is the first one called when instantiating a StatefulWidget. It creates the State object associated with the widget. This method is automatically called by the Flutter framework when the widget is inserted into the widget tree for the first time.

2

What is the correct order of lifecycle methods when a StatefulWidget is created?

Respuesta

The correct order is: createState() creates the State object, then initState() initializes the state, didChangeDependencies() is called after initState and whenever dependencies change, and finally build() constructs the UI. This sequence ensures the state is properly initialized before rendering.

3

What is the main purpose of the initState() method?

Respuesta

initState() is used to initialize data that depends on context or to set up listeners, animation controllers and subscriptions. This method is only called once when the State object is created, making it the ideal place for one-time initializations.

4

Why is it mandatory to call super.initState() in initState()?

5

What happens when setState() is called in a StatefulWidget?

+17 preguntas de entrevista

Domina Flutter para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis