Create button to reset the counter
Solution 1:
First of all you need to create a new button with that functionality of resetting your counter variable. Wrap your center widget with a column and add a new button like this:
Column(
children: [
Center(
child: Text(
"Contador\n$count",
textAlign: TextAlign.center,
),
),
ElevatedButton(
child: const Text("Reset Counter"),
onPressed: () {
setState(() {
count = 0;
});
},
),
],
),
In order to see the counter updating on your screen you have to call the increment method inside of setState() so the framework schedules a rebuild!
void increment() {
setState(() {
count++;
});
}
I suggest you do some tutorials on the official flutter site to get started with the core fundamentals of flutter - happy coding! :)