I have created a quiz app using Flutter and Laravel, Everything is working fine except for Timer.
The Time is reduced multiple times for question no. as
Reduces means if I given 60 seconds for each question then in the first que. it is okay but in 2nd ques. it starting from 60 the 58 the 56 then 54 sec..
and in 3rd, it starts from 60 then 57 then 54.. this way.
- first question timer reduces 1 second.
- in the second question, it reduces to 2 seconds.
- in the third question it reduces 3 seconds and
- after 10 questions it only is there for a few seconds
int timer = 60;
String showtimer = "60";
bool canceltimer = false;
Here is the timer function
void startTimer() async {
const oneSec = Duration(seconds: 1);
Timer.periodic(oneSec, (Timer t) {
setState(() {
if (timer < 1) {
t.cancel();
this.nextQuestion(context);
} else if (canceltimer == true) {
t.cancel();
} else {
timer = timer - 1;
}
showtimer = timer.toString();
});
});
}
And in the nextQuestion method, I am further calling showtimer function
