startTimer method
- required int timeLimit,
- required VoidCallback onFinish,
- required ProgressProvider pp,
This function is called to start the timer when the test starts.
It requires the following arguments:
timeLimit duration of the test in milliseconds
onFinish callback of the function that is to be executed when the time expires
pp the instance of ProgressProvider so that the
ProgressProvider.thirdsCounter can be updated
Implementation
void startTimer({required int timeLimit, required VoidCallback onFinish, required ProgressProvider pp}) {
debugPrint('Time started');
testTimer?.cancel();
startTime = DateTime.now();
limitMilliseconds= timeLimit;
isTestRunning = true;
//Incrementando a mano los intervalos de tiempo cada 100 ms (elapsed += 100) iba muy lento. Mejor con DateTime.now
/// Each 100 milliseconds the timer is updated
testTimer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
final currentElapsed = elapsedMilliseconds;
if(currentElapsed >= timeLimit){
testTimer!.cancel();
isTestRunning = false;
onFinish();
notifyListeners();
return;
}
pp.updateThirdsCounter(elapsedMilliseconds, limitMilliseconds);
notifyListeners(); });
}