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
- Start a 501 game with 2+ players.
- Record 3 darts for Player 1 — the turn ends and switches to Player 2.
- Tap Undo.
- Expected: back to Player 1's turn with 2 darts already shown.
- 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
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
Root cause
undoLastThrow()inlib/providers/game_provider.dart(~line 238) does not restorecurrentPlayerIndex,currentRound, orcurrentTurnThrowswhen the undone throw belonged to a different player than the current one.Fix
Before updating state, check whether
last.playerId != currentPlayer.id. If so:currentPlayerIndexto the index oflast.playerIdcurrentTurnThrowsfromnewAllThrowsfiltered to the same player, round, and dart numbers preceding the undone dartcurrentRoundif the undone throw was dart 1 of a new round