Flutter

Basic State Management

setState, InheritedWidget, Provider basics, scoped state, lifting state up

22 면접 질문·
Mid-Level
1

What is the main purpose of setState in a StatefulWidget?

답변

setState notifies the Flutter framework that the widget's internal state has changed and it needs to rebuild the widget. When setState is called, Flutter schedules a rebuild of the widget to reflect the new state values. Without calling setState, changes to state variables would not trigger a visual update.

2

What happens if a state variable is modified without calling setState?

답변

Without calling setState, Flutter is not notified of the change and does not schedule a rebuild. The variable is modified in memory but the user interface remains unchanged until the next rebuild triggered by another cause. This is a common beginner mistake that leads to hard-to-identify bugs.

3

In what order should modifications be made when calling setState?

답변

State modifications should be made inside the setState callback. This allows Flutter to trace changes and schedule the rebuild synchronously. While modifying before or after technically works, the convention is to modify inside for code clarity and change traceability.

4

Why is it discouraged to call setState in initState?

5

What is the main role of an InheritedWidget in Flutter?

+19 면접 질문

다음 면접을 위해 Flutter을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기