โ Map
State Kingdom ยท Level 3
setState makes the UI react
A
StatefulWidget
holds mutable data. Changing a field
alone
isn't enough โ you must wrap the change in
setState
so Flutter rebuilds the widget.
Pick the correct handler, then tap the switch.
What should
onPressed
do?
isOn = !isOn;
setState(() { isOn = !isOn; });
build();
Preview
๐
isOn =
false
Toggle light
Pick the right handler to enable the switch.
โ Widget City