Skip to content

Commit

Permalink
Ensure to clear animation state each time the board updates
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Sep 6, 2024
1 parent e034d87 commit 6457493
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/src/widgets/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ class _BoardState extends State<Chessboard> {
blindfoldMode: widget.settings.blindfoldMode,
upsideDown: _isUpsideDown(entry.value.color),
onComplete: () {
setState(() {
fadingPieces.remove(entry.key);
});
fadingPieces.remove(entry.key);
},
),
),
Expand All @@ -296,7 +294,7 @@ class _BoardState extends State<Chessboard> {
),
for (final entry in translatingPieces.entries)
PositionedSquare(
key: ValueKey('${entry.key.name}-${entry.value.piece}-translating'),
key: ValueKey('${entry.key.name}-${entry.value.piece}'),
size: widget.size,
orientation: widget.orientation,
square: entry.key,
Expand All @@ -306,9 +304,7 @@ class _BoardState extends State<Chessboard> {
orientation: widget.orientation,
duration: widget.settings.animationDuration,
onComplete: () {
setState(() {
translatingPieces.remove(entry.key);
});
translatingPieces.remove(entry.key);
},
child: PieceWidget(
piece: entry.value.piece,
Expand Down Expand Up @@ -428,6 +424,9 @@ class _BoardState extends State<Chessboard> {
return;
}

translatingPieces = {};
fadingPieces = {};

final newPieces = readFen(widget.fen);

if (widget.settings.animationDuration > Duration.zero) {
Expand Down
3 changes: 2 additions & 1 deletion test/widgets/board_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ void main() {
await tester.tapAt(squareOffset(Square.e4));
await tester.pump();

expect(find.byKey(const Key('e4-whitepawn-translating')), findsOneWidget);
expect(find.byKey(const Key('e4-whitepawn')), findsOneWidget);
expect(find.byKey(const Key('e2-selected')), findsNothing);
expect(find.byType(ValidMoveHighlight), findsNothing);

// wait for the animations to finish
await tester.pumpAndSettle();

expect(find.byKey(const Key('e4-whitepawn')), findsOneWidget);
Expand Down

0 comments on commit 6457493

Please sign in to comment.