answerQuestion method

void answerQuestion(
  1. int selectedIndex
)

Implementation

void answerQuestion(int selectedIndex) {
  final isCorrect =
      selectedIndex == state.questions[state.currentIndex].correctAnswer;
  final newScore = isCorrect ? state.score + 1 : state.score;

  if (state.currentIndex < state.questions.length - 1) {
    state = state.copyWith(
      currentIndex: state.currentIndex + 1,
      score: newScore,
      timeLeft: 10,
    );
  } else {
    state = state.copyWith(score: newScore, isFinished: true);
  }
}