Open up stopwatch.dart to get started:
- The first thing you are going to do is make the timer a bit more precise. Seconds are not a very interesting value to use for stopwatches.
- Use the refactoring tools to rename the seconds property to milliseconds. We also need to update the onTick, _startTimer, and _secondsText methods:
int milliseconds = 0;
void _onTick(Timer time) {
setState(() {
milliseconds += 100;
});
}
void _startTimer() {
timer = Timer.periodic(Duration(milliseconds: 100), _onTick);
...
}
String _secondsText(int milliseconds) {
final seconds = milliseconds / 1000;
return '$seconds seconds';
}
- Now, let's add a laps list so that we can keep track of the values for each lap. We're going to add to this list every time the user taps a lap button.
- Add this property to the top of the StopWatchState class, just under the declaration of the timer:
final laps = <int>[];
- Create a...