Skip to content

Undo does not revert player turn when crossing a turn boundary #11

@BySplashGm

Description

@BySplashGm

Bug description

Tapping Undo after the third dart of a turn (which triggered the automatic player switch) does not switch back to the previous player. The active player remains wrong and their three dart slots are shown as empty instead of restoring the two throws that preceded the undone one.

Steps to reproduce

  1. Start a 501 game with 2+ players.
  2. Record 3 darts for Player 1 — the turn ends and switches to Player 2.
  3. Tap Undo.
  4. Expected: back to Player 1's turn with 2 darts already shown.
  5. Actual: still on Player 2 with an empty turn.

Root cause

undoLastThrow() in lib/providers/game_provider.dart (~line 238) does not restore currentPlayerIndex, currentRound, or currentTurnThrows when the undone throw belonged to a different player than the current one.

// currentPlayerIndex and currentRound are never touched — always wrong
// currentTurnThrows is sliced from the *current* player's throws,
// which are empty when the boundary was just crossed
final newTurnThrows = s.currentTurnThrows.isEmpty
    ? s.currentTurnThrows   // ← stays empty; previous player's throws are lost
    : s.currentTurnThrows.sublist(0, s.currentTurnThrows.length - 1);

Fix

Before updating state, check whether last.playerId != currentPlayer.id. If so:

  • Restore currentPlayerIndex to the index of last.playerId
  • Rebuild currentTurnThrows from newAllThrows filtered to the same player, round, and dart numbers preceding the undone dart
  • Decrement currentRound if the undone throw was dart 1 of a new round

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions