Widgets Interview Questions (Flutter)
10 Widgets questions from the Flutter track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Junior
When do you use StatelessWidget and what does build mean in it?
A StatelessWidget describes the UI from fixed configuration, and build returns a new widget tree when Flutter asks to update it.
Read the full explanation - Mid-level
Explain the basic lifecycle of a StatefulWidget's State.
A State usually goes through initState, then didChangeDependencies and build, may receive didUpdateWidget, then dispose on final removal.
Read the full explanation - Mid-level
What is BuildContext and why does its position in the tree matter?
BuildContext is a handle to a widget's position inside the element tree, and through it you look up ancestors such as Theme or an InheritedWidget.
Read the full explanation - Mid-level
How do keys help Flutter preserve widget identity?
A key lets Flutter match a new widget with a previous element when the order or set of siblings changes, thereby preserving the correct state.
Read the full explanation - Junior
Explain the rule constraints go down, sizes go up in Flutter.
The parent sends constraints to the child, the child picks a size within them, and then the parent positions it.
Read the full explanation - Mid-level
How do const widgets help reduce the cost of a rebuild?
const creates a configuration that can be shared at compile time, which lets Flutter skip static parts and do less checking during an update.
Read the full explanation - Junior
What does setState actually do, and how do you avoid a wide rebuild?
setState tells the framework that the State changed and requests a rebuild of the StatefulElement and its children; put the state at the nearest logical owner.
Read the full explanation - Mid-level
When do you use InheritedWidget and didChangeDependencies?
An InheritedWidget shares a value across the tree, and didChangeDependencies notifies the State when a dependency it registered through the context changes.
Read the full explanation - Mid-level
What are the trade-offs of using GlobalKey in Flutter?
A GlobalKey gives access and a unique identity across the tree, but it is more expensive and more tightly coupled than local keys and must not be created inside build.
Read the full explanation - Mid-level
How do you use the child parameter in a Builder to reduce rebuilds?
Put the static subtree in child outside the builder and pass it through as is; when the builder is called, only the part that depends on the value is rebuilt.
Read the full explanation