novaRodada method

Future<void> novaRodada(
  1. double widthPx, {
  2. bool repeat = false,
})

Renderiza e começa uma rodada nova na caixa de widthPx. Com repeat, refaz a última, igual (ver ExerciseSource.repeatRound).

Implementation

Future<void> novaRodada(double widthPx, {bool repeat = false}) async {
  // Uma rodada pedida por cima de outra que ainda carrega (a caixa mudou de
  // tamanho ao esconder as barras do sistema, ao girar) deixa a antiga velha:
  // ela desiste a cada espera e descarta o que já montou.
  final token = ++_roundToken;
  bool stale() => !_vivo || token != _roundToken;
  _diagRequest(widthPx, repeat: repeat, token: token);
  // A rodada que o aluno deixou no meio entrega o que tocou antes de a nova começar
  // (TC13): o `roundStarted` zera as teclas dela no sink.
  _entregarInterrompida();
  // A execução da rodada (TC08) começa aqui: o que o teclado tocar daqui em diante
  // é dela. Não se avisa o sink do aluno virtual (ele não conta nada).
  if (!virtualRun) deps.timeSink.roundStarted();
  _soltarRodada();
  listen.parar();
  _emitir(
    state.copyWith(
      repeating: repeat,
      loading: true,
      error: null,
      result: null,
      verdict: null,
      questionRound: null,
      courseUse: null,
      chart: ExerciseChartState.vazio,
    ),
  );
  try {
    final round = repeat
        ? await source.repeatRound()
        : await source.nextRound(_rng, roundIndex: state.roundNumber);
    if (stale()) return;
    _emitir(state.copyWith(courseUse: source.courseUseOf(round)));
    await _despachar(round, (widthPx: widthPx, token: token, stale: stale));
  } on UnimplementedError catch (e) {
    if (stale()) return;
    _falhar('$e');
  } on Object catch (e, st) {
    DiagLog.log('erro', 'exercício: erro ao montar a rodada: $e\n$st');
    if (stale()) return;
    _falhar(kRoundFailedText);
  }
}