Google Flutter Essentials 3 — Questions and Answers
Question 1: What is the key difference between StatelessWidget and StatefulWidget?
- StatefulWidget can rebuild in response to changing internal state (Correct answer)
- StatelessWidget is faster to compile
- StatefulWidget cannot have children
- StatelessWidget requires a State object
Correct answer: StatefulWidget can rebuild in response to changing internal state
StatefulWidget holds mutable state and can rebuild when that state changes.
Question 2: Which method triggers a rebuild of a StatefulWidget after state changes?
- setState() (Correct answer)
- rebuild()
- update()
- refresh()
Correct answer: setState()
Calling setState() notifies the framework to rebuild the widget.
Question 3: Which widget arranges its children vertically?
- Column (Correct answer)
- Row
- Stack
- Wrap
Correct answer: Column
Column lays out its children along the vertical axis.
Question 4: Which widget arranges its children horizontally?
- Row (Correct answer)
- Column
- ListView
- Center
Correct answer: Row
Row lays out its children along the horizontal axis.
Question 5: Which property controls spacing of children along the main axis?
- mainAxisAlignment (Correct answer)
- crossAxisAlignment
- textDirection
- verticalDirection
Correct answer: mainAxisAlignment
mainAxisAlignment positions children along the main axis of a Row or Column.
Question 6: What is the lifecycle method called once when a State object is inserted into the tree?
- initState() (Correct answer)
- build()
- dispose()
- didUpdateWidget()
Correct answer: initState()
initState() runs once when the State is first created and inserted.
Question 7: Which method should release resources like controllers when a widget is removed?
- dispose() (Correct answer)
- deactivate()
- remove()
- close()
Correct answer: dispose()
dispose() is called when the State is permanently removed, ideal for cleanup.
What is the key difference between StatelessWidget and StatefulWidget?