Skip to content

Commit

Permalink
Improve BoardThumbnail with a board optimized for scrollables
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Oct 31, 2024
1 parent 8a0c93d commit 820ec0e
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions lib/src/widgets/board_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BoardThumbnail extends ConsumerStatefulWidget {
this.footer,
this.lastMove,
this.onTap,
this.animationDuration,
});

const BoardThumbnail.loading({
Expand All @@ -24,7 +25,8 @@ class BoardThumbnail extends ConsumerStatefulWidget {
}) : orientation = Side.white,
fen = kInitialFEN,
lastMove = null,
onTap = null;
onTap = null,
animationDuration = null;

/// Size of the board.
final double size;
Expand All @@ -46,6 +48,9 @@ class BoardThumbnail extends ConsumerStatefulWidget {

final GestureTapCallback? onTap;

/// Optionally animate changes to the board by the specified duration.
final Duration? animationDuration;

@override
_BoardThumbnailState createState() => _BoardThumbnailState();
}
Expand All @@ -67,20 +72,32 @@ class _BoardThumbnailState extends ConsumerState<BoardThumbnail> {
Widget build(BuildContext context) {
final boardPrefs = ref.watch(boardPreferencesProvider);

final board = Chessboard.fixed(
size: widget.size,
fen: widget.fen,
orientation: widget.orientation,
lastMove: widget.lastMove as NormalMove?,
settings: ChessboardSettings(
enableCoordinates: false,
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
boxShadow: boardShadows,
animationDuration: const Duration(milliseconds: 150),
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
),
);
final board = widget.animationDuration != null
? Chessboard.fixed(
size: widget.size,
fen: widget.fen,
orientation: widget.orientation,
lastMove: widget.lastMove as NormalMove?,
settings: ChessboardSettings(
enableCoordinates: false,
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
boxShadow: boardShadows,
animationDuration: widget.animationDuration!,
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
),
)
: StaticChessboard(
size: widget.size,
fen: widget.fen,
orientation: widget.orientation,
lastMove: widget.lastMove as NormalMove?,
enableCoordinates: false,
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
boxShadow: boardShadows,
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
);

final maybeTappableBoard = widget.onTap != null
? GestureDetector(
Expand Down

0 comments on commit 820ec0e

Please sign in to comment.