respostaBotao method

void respostaBotao(
  1. int index
)

Um botão de resposta (answerChoice). Com answerCues (EX16, degrees), o botão toca o trecho com o acorde dele, certo ou não.

Implementation

void respostaBotao(int index) {
  if (_session.done ||
      _session.revealing ||
      state.review.reviewIndex != null) {
    return;
  }
  final cues = _session.current?.answerCues ?? const <BeatCue>[];
  if (index < cues.length) unawaited(tocarBeat(cues[index]));
  final result = _session.answerChoice(index);
  if (result == null) return;
  if (result) {
    if (state.answer.wrongButton != null) {
      _emitir(
        state.copyWith(
          answer: state.answer.copyWith(wrongButton: () => null),
        ),
      );
    }
    _afterAnswer();
  } else {
    _emitir(
      state.copyWith(
        answer: state.answer.copyWith(
          wrongButton: () => index,
          explainedAt: () => _session.index,
        ),
      ),
    );
    _flashTimer?.cancel();
    _flashTimer = clock.timer(const Duration(milliseconds: 500), () {
      if (isClosed) return;
      _emitir(
        state.copyWith(
          answer: state.answer.copyWith(wrongButton: () => null),
        ),
      );
    });
  }
}