Buttons in Flutter are pretty simple – they are just widgets that accept a function. These functions are then executed when the button detects an interaction. If a null value is supplied to the onPressed property, Flutter considers the button to be disabled.
Flutter has several button types that can be used for different aesthetics, but their functionality is the same. They are as follows:
- ElevatedButton
- TextButton
- IconButton
- FloatingActionButton
- DropDownButton
- CupertinoButton
You can play around with any of these widgets until you find a button that matches your desired look.
In this recipe, we wrote the onPressed functions out as methods in the StopWatchState class, but it is perfectly acceptable to throw them into the functions as closures. We could have written the buttons like this:
ElevatedButton(
child: Text('Start'),
onPressed: isTicking
? null
: () {
timer = Timer...