Counter with StatefulWidget
Build a counter screen with + and − buttons using setState.
beginnerDart / Flutter· Flutter & Dart
The task
Make a CounterScreen that shows a number in the middle of the screen, starting at 0:
- A + button adds 1, a − button subtracts 1.
- The number never goes below 0.
- Use a
StatefulWidgetand callsetStatewhenever the number changes.
Flutter doesn't run in the browser here: write it, ask the AI tutor to review it, and try it in your own Flutter project (or DartPad).
What you'll build
The finished app screen, as a web preview (yours will run on a phone or emulator). Try it, then build it below.