when I call timer.cancel (), the clock stops working. But when calling back to start a new session, I discover that the _u variable in the old session still counts from itself and parallel with new one.
Please help !
startTime(60);
timer.cancel();# It worked.
timer = null;
startTime(60);# but when recall. It working with 2 session. (old and new)
//Call timer.cancel() _u variable stop at 40.
//Recall startTime() _u variable counts with 2 session (40) and (60)
startTime(reset){
int _u = reset;
const oneSec = const Duration(seconds: 1);
timer = Timer.periodic(
oneSec,
(Timer timer) => setState(
() {
if (_u < 1) {
timer.cancel();
// call my handle
} else {
_u = _u -1;
if(_u <0){
timer?.cancel();
}
}
},
),
);