startTimer method
Implementation
void startTimer() async {
countdownTimer?.cancel();
_updateTimer?.cancel();
remainingSeconds = 0;
_startTime = DateTime.now();
setState(() {
isTestRunning = true;
hasTestStarted = true;
});
test = await saveInitialTest();
// 1-second countdown timer
countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() {
remainingSeconds++;
});
final selectedDuration = timerOptions[selectedValue] ?? 0;
if (selectedDuration > 0 && remainingSeconds >= selectedDuration) {
endTest();
}
});
// 30-second update timer
_updateTimer = Timer.periodic(const Duration(seconds: 30), (_) {
if (isTestRunning) {
print('🟡 Auto-updating test...');
_updateTest();
} else {
print('🛑 Stopping update timer');
_updateTimer?.cancel();
}
});
}