Flutter

Basic State Management

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

22 domande da colloquioยท
Mid-Level
1

What is the main purpose of setState in a StatefulWidget?

Risposta

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?

Risposta

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?

Risposta

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 domande da colloquio

Padroneggia Flutter per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis