0
0
Fluttermobile~20 mins

Checkbox and Switch in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Checkbox and Switch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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;
  },
);
AThrows an error
Btrue
Cnull
Dfalse
Attempts:
2 left
💡 Hint
Think about how the checkbox toggles its value each tap.
📝 Syntax
intermediate
2:00remaining
Correct Switch Widget Syntax
Which option shows the correct syntax to create a Switch widget that toggles a boolean isSwitched variable in Flutter?
ASwitch(value: isSwitched, onChanged: (value) => isSwitched == value)
BSwitch(isOn: isSwitched, onToggle: (value) => isSwitched = value)
CSwitch(value: isSwitched, onChanged: (bool value) { setState(() { isSwitched = value; }); })
DSwitch(state: isSwitched, onChanged: (bool value) { isSwitched = value; })
Attempts:
2 left
💡 Hint
Check the official Flutter Switch widget properties.
lifecycle
advanced
2: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
  },
);
AThe checkbox UI does not update to reflect the new value.
BThe checkbox UI updates correctly anyway.
CThe app crashes with an error.
DThe checkbox toggles but reverts immediately.
Attempts:
2 left
💡 Hint
Remember how Flutter knows to redraw widgets.
navigation
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?
ANavigator.pushNamed(context, '/screenB'); // isChecked is global variable
BNavigator.push(context, MaterialPageRoute(builder: (_) => ScreenB(isChecked: isChecked)));
CNavigator.push(context, MaterialPageRoute(builder: (_) => ScreenB())); // ScreenB reads isChecked directly
DNavigator.pop(context, isChecked);
Attempts:
2 left
💡 Hint
Think about how to send data when opening a new screen.
🔧 Debug
expert
2: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;
    },
  );
}
ABecause setState is not called, so UI does not rebuild.
BBecause the value property is incorrectly set to false.
CBecause onChanged callback is missing.
DBecause Switch requires a controller to toggle.
Attempts:
2 left
💡 Hint
How does Flutter know to redraw widgets?