Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/src/widgets/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,27 @@ class BoardWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final safeFen = fen.trim().isNotEmpty ? fen : Setup.standard.fen;
final Chess position = Chess.fromSetup(Setup.parseFen(safeFen));
// ✅ Safe fallback for spectator mode
final effectiveGameData =
gameData ??
GameData(
playerSide: PlayerSide.none, // spectator cannot move
sideToMove: position.turn, // doesn’t matter, just required
validMoves: IMap(), // no valid moves
promotionMove: null,
isCheck: position.isCheck,
premovable: null,
onMove: (_, {isDrop}) {}, // no-op
onPromotionSelection: (_) {}, // no-op
);
final board = Chessboard(
key: boardKey,
size: size,
fen: fen,
fen: safeFen,
orientation: orientation,
game: gameData,
game: effectiveGameData,
lastMove: lastMove,
shapes: shapes,
settings: settings,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/widgets/game_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ class _GameLayoutState extends ConsumerState<GameLayout> {
final shapes = userShapes.union(widget.shapes ?? ISet());
final slicedMoves = widget.moves?.asMap().entries.slices(2);

final fen = widget.interactiveBoardParams?.position.fen ?? widget.fen!;
final fenCandidate = widget.interactiveBoardParams?.position.fen ?? widget.fen;
final fen = (fenCandidate?.isNotEmpty ?? false) ? fenCandidate! : Setup.standard.fen;

final gameData = widget.interactiveBoardParams != null
? boardPrefs.toGameData(
variant: widget.interactiveBoardParams!.variant,
Expand Down
Loading