I just got back to Flutter, and wanted to test the countdown for a simple practice app. I can scroll the countdown second by second but I haven't figured out how to do it with the milliseconds.
the current code:
import 'package:quiver/async.dart';
int _start = 10;
int _current = 10;
void startTimer() {
CountdownTimer countDownTimer = CountdownTimer(
Duration(seconds: _start),
const Duration(seconds: 1),
);
var sub = countDownTimer.listen(null);
sub.onData((duration) {
setState(() {
int _current = _start - duration.elapsed.inSeconds;
dureedefaut = _current;
});
});
}
I updated on my page the variable : dureedefaut
Thank you for your help
CodePudding user response:
Simply use this : Duration(milliseconds: )
you can use milisecond , second and etc in Duration Widget
CodePudding user response:
Thank you, I tested but the countdown no longer stops at 0 but sometimes has negative numbers
void startTimer() {
CountdownTimer countDownTimer = CountdownTimer(
Duration(milliseconds: _start),
const Duration(milliseconds: 1),
);
var sub = countDownTimer.listen(null);
sub.onData((duration) {
setState(() {
_current = _start - duration.elapsed.inMilliseconds;
dureedefaut = _current;
});
});
}