0
0
Fluttermobile~5 mins

StatefulWidget in Flutter - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a StatefulWidget in Flutter?
A StatefulWidget is a widget that can change its appearance over time because it holds some state information that can be updated.
Click to reveal answer
beginner
What method do you override to create the mutable state for a StatefulWidget?
You override the <code>createState()</code> method to return an instance of a State subclass that holds the widget's mutable state.
Click to reveal answer
beginner
How do you update the UI when the state changes in a StatefulWidget?
You call <code>setState(() { ... })</code> inside the State class to tell Flutter to rebuild the widget with the new state.
Click to reveal answer
intermediate
Why should you avoid putting mutable state inside the StatefulWidget class itself?
Because the StatefulWidget is immutable; the mutable state belongs in the separate State class to keep UI and state logic separate.
Click to reveal answer
intermediate
What lifecycle method is called when a StatefulWidget is first inserted into the widget tree?
The initState() method is called once when the State object is created and inserted into the tree.
Click to reveal answer
Which method must you override to create the state for a StatefulWidget?
Adispose()
Bbuild()
CinitState()
DcreateState()
What does calling setState() inside a State class do?
ARebuilds the widget with updated state
BPauses the app
CCreates a new StatefulWidget
DDeletes the widget
Where should you store mutable state in a StatefulWidget?
AInside the StatefulWidget class
BIn a separate StatelessWidget
CInside the State class
DIn the main() function
Which lifecycle method is called only once when the State object is created?
AinitState()
Bdispose()
Cbuild()
DdidUpdateWidget()
What happens if you forget to call setState() after changing state variables?
AThe app will crash
BThe UI will not update
CThe widget will rebuild automatically
DThe state will reset
Explain how StatefulWidget and its State class work together to manage changing UI.
Think about how a widget can change on screen when you press a button.
You got /4 concepts.
    Describe the purpose of the initState() method in the lifecycle of a StatefulWidget.
    When you first open an app screen, what setup might you need?
    You got /4 concepts.