A Checkbox widget lets users select or deselect an option. It shows a small box that can be checked or unchecked.
Click to reveal answer
beginner
How does a Switch widget differ from a Checkbox in Flutter?
A Switch widget is a toggle button that slides between ON and OFF states, often used for settings. A Checkbox is a box that can be checked or unchecked.
Click to reveal answer
beginner
Which property controls whether a Checkbox or Switch is selected or not?
The 'value' property controls if the Checkbox or Switch is selected (true) or not (false).
Click to reveal answer
beginner
What is the purpose of the 'onChanged' callback in Checkbox and Switch widgets?
The 'onChanged' callback runs when the user taps the widget. It lets the app update the state to reflect the new selection.
Click to reveal answer
intermediate
How can you make a Checkbox or Switch disabled in Flutter?
Set the 'onChanged' property to null. This disables the widget and prevents user interaction.
Click to reveal answer
What type of value does the 'value' property of a Checkbox expect?
AList
BBoolean (true or false)
CInteger
DString
✗ Incorrect
The 'value' property expects a boolean to indicate if the Checkbox is checked (true) or unchecked (false).
Which widget would you use to let users toggle a setting ON or OFF with a sliding button?
ASwitch
BCheckbox
CRadio
DSlider
✗ Incorrect
The Switch widget provides a sliding toggle button for ON/OFF states.
How do you disable a Checkbox so the user cannot change its state?
AWrap it in a Disabled widget
BSet 'value' to false
CSet 'enabled' to false
DSet 'onChanged' to null
✗ Incorrect
Setting 'onChanged' to null disables the Checkbox and prevents user interaction.
What happens when the user taps a Checkbox with a valid 'onChanged' callback?
ANothing happens
BThe app crashes
CThe Checkbox toggles its state and 'onChanged' runs
DThe Checkbox disappears
✗ Incorrect
Tapping toggles the Checkbox and triggers the 'onChanged' callback to update the app state.
Which property do you use to listen for changes in a Switch widget?
AonChanged
BonSwitch
ConTap
DonToggle
✗ Incorrect
The 'onChanged' property listens for user toggles on the Switch widget.
Explain how to create a Checkbox in Flutter that updates its state when tapped.
Think about how the Checkbox knows if it is checked and how to update that.
You got /4 concepts.
Describe the differences and typical uses of Checkbox and Switch widgets in Flutter.
Consider how users interact with each and what UI they expect.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between a Checkbox and a Switch in Flutter?
easy
A. Checkbox requires a controller; Switch does not.
B. Checkbox allows multiple selections; Switch is for a single on/off choice.
C. Checkbox changes color automatically; Switch does not.
D. Checkbox is only for iOS; Switch is only for Android.
Solution
Step 1: Understand Checkbox behavior
A Checkbox lets users select multiple options independently.
Step 2: Understand Switch behavior
A Switch is a toggle for a single on/off setting, not multiple selections.
Final Answer:
Checkbox allows multiple selections; Switch is for a single on/off choice. -> Option B
Quick Check:
Checkbox = multiple, Switch = single toggle [OK]
Hint: Checkbox = multiple choices, Switch = single toggle [OK]
Common Mistakes:
Thinking Switch can select multiple options
Confusing platform-specific behavior
Assuming Checkbox needs a controller
2. Which of the following is the correct way to create a Checkbox widget with a boolean value isChecked and update it on change?
The variable checked is updated but not inside setState.
Step 2: Understand Flutter UI update
Without setState, the UI will not rebuild to reflect the new value.
Final Answer:
Missing setState call to update the UI. -> Option A
Quick Check:
State changes need setState for UI refresh [OK]
Hint: Use setState to refresh UI after state changes [OK]
Common Mistakes:
Forgetting setState causes no UI update
Thinking Checkbox needs a controller
Confusing parameter types
5. You want to create a settings page with two options: "Enable Notifications" (Switch) and "Accept Terms" (Checkbox). How should you manage their states to update the UI correctly when toggled?
hard
A. Use two boolean variables and update each inside setState when toggled.
B. Use a single boolean variable for both widgets and update it in setState.
C. Use final variables since the UI does not need to change after initial build.
D. Use global variables outside the widget and update them without setState.
Solution
Step 1: Identify separate states
Each widget needs its own boolean variable to track its state independently.
Step 2: Update states with setState
Wrap each state change inside setState to rebuild the UI correctly.
Final Answer:
Use two boolean variables and update each inside setState when toggled. -> Option A
Quick Check:
Separate booleans + setState = correct UI update [OK]
Hint: Use separate booleans and setState for each toggle [OK]
Common Mistakes:
Using one variable for multiple toggles
Not using setState causing UI freeze
Using final variables preventing changes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.