Complete the code to update the counter when the button is pressed.
int _counter = 0; void _incrementCounter() { setState(() { _counter [1] 1; }); }
We use += to add 1 to the counter inside setState so the UI updates.
Complete the code to call setState and update the message string.
String _message = 'Hello'; void _changeMessage() { [1](() { _message = 'Hi there!'; }); }
setState is the Flutter method to tell the framework to rebuild the widget with new data.
Fix the error in the code by completing the setState call correctly.
int _count = 0; void increment() { setState [1] { _count++; } }
setState requires parentheses around the function, like setState(() { ... }).
Fill both blanks to correctly update the boolean flag inside setState.
bool _isOn = false;
void toggle() {
setState([1] {
_isOn [2] !_isOn;
});
}The setState method requires parentheses () around the function, and the function body uses curly braces {}.
Fill all three blanks to correctly update a list inside setState.
List<String> _items = [];
void addItem(String item) {
setState([1] {
_items.[2](item);
});
}We call setState with parentheses (). To add one item to the list, use add.