Flutter

Widget Lifecycle

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

20 mülakat soruları·
Junior
1

Which method is called first when creating a StatefulWidget?

Cevap

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?

Cevap

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?

Cevap

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 mülakat soruları

Bir sonraki mülakatın için Flutter'de uzmanlaş

Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.

Ücretsiz başla