goToDialog function

AlertDialog goToDialog(
  1. BuildContext context,
  2. TrainingStep step,
  3. SightProgress? now
)

Confirma voltar a step (ou reiniciar, no 1a). O sem fim guarda a melhor volta; reiniciar a zera, e voltar a um passo mantém a guardada.

Implementation

AlertDialog goToDialog(
  BuildContext context,
  TrainingStep step,
  SightProgress? now,
) {
  final reset = step.index == 0;
  final best = now == null ? 0 : max(now.lapBest, now.lap);
  final endlessNote = best == 0
      ? ''
      : reset
      ? ' A melhor volta do sem fim (volta $best) também é zerada.'
      : ' A melhor volta do sem fim (volta $best) fica guardada; ao '
            'voltar a ele, você recomeça na volta 1.';
  return AlertDialog(
    title: Text(reset ? 'Reiniciar do 1a?' : 'Voltar ao ${step.name}?'),
    content: Text(
      '${reset ? 'Os passos feitos' : 'Os passos depois de ${step.name}'} '
      'ficam para refazer. As rodadas limpas e as respostas de ouvido do '
      'passo atual são apagadas.$endlessNote',
    ),
    actions: [
      TextButton(
        onPressed: () => Navigator.pop(context, false),
        child: const Text('Cancelar'),
      ),
      FilledButton(
        style: FilledButton.styleFrom(backgroundColor: context.zt.colors.bad),
        onPressed: () => Navigator.pop(context, true),
        child: Text(reset ? 'Reiniciar' : 'Voltar'),
      ),
    ],
  );
}