1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| int countValue = 10; Timer _timer;
void startTimer() { final Duration duration = Duration(seconds: 1); cancelTimer();
_timer = Timer.periodic(duration, (timer) { countValue = countValue - 1; if (this.mounted) { setState((){ }); } print(countValue); if (countValue <= 0) { cancelTimer(); } }); }
|