Challenge - 5 Problems
Checkbox and Switch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Checkbox State Change Behavior
What will be the value of the variable
isChecked after tapping the checkbox twice in this Flutter code snippet?Flutter
bool isChecked = false; Checkbox( value: isChecked, onChanged: (bool? value) { isChecked = value ?? false; }, );
Attempts:
2 left
💡 Hint
Think about how the checkbox toggles its value each tap.
✗ Incorrect
The checkbox toggles from false to true on the first tap, then true to false on the second tap. After two taps, it returns to false. But since the question asks after tapping twice, the final value is false.
📝 Syntax
intermediate2:00remaining
Correct Switch Widget Syntax
Which option shows the correct syntax to create a Switch widget that toggles a boolean
isSwitched variable in Flutter?Attempts:
2 left
💡 Hint
Check the official Flutter Switch widget properties.
✗ Incorrect
Option C uses the correct property names and updates the state properly inside setState. Other options use wrong property names or incorrect assignment.
❓ lifecycle
advanced2:00remaining
State Update Timing with Checkbox
In a StatefulWidget, if you update the checkbox state variable
isChecked without calling setState(), what happens to the UI?Flutter
bool isChecked = false; Checkbox( value: isChecked, onChanged: (bool? value) { isChecked = value ?? false; // Missing setState call }, );
Attempts:
2 left
💡 Hint
Remember how Flutter knows to redraw widgets.
✗ Incorrect
Without calling setState, Flutter does not know the state changed, so it does not rebuild the widget. The UI stays the same even if the variable changes.
advanced
2:00remaining
Passing Checkbox State Between Screens
You want to pass the checkbox state
isChecked from Screen A to Screen B in Flutter. Which approach correctly passes the value during navigation?Attempts:
2 left
💡 Hint
Think about how to send data when opening a new screen.
✗ Incorrect
Option B passes the value explicitly via the constructor when navigating. Option B assumes a global variable which is not safe. Option B does not pass the value. Option B is for returning data back, not passing forward.
🔧 Debug
expert2:00remaining
Why Does the Switch Not Toggle Visually?
Given this Flutter code snippet, why does the Switch not visually toggle when tapped?
Flutter
bool isSwitched = false; Widget build(BuildContext context) { return Switch( value: isSwitched, onChanged: (bool value) { isSwitched = value; }, ); }
Attempts:
2 left
💡 Hint
How does Flutter know to redraw widgets?
✗ Incorrect
Without calling setState, Flutter does not rebuild the widget tree, so the visual state does not update even if the variable changes.