BoardController constructor

BoardController({
  1. required PieceSet pieceSet,
  2. required BoardState state,
  3. required BoardTheme theme,
  4. BoardSize size = const BoardSize(8, 8),
  5. HighlightTheme? highlightTheme,
  6. dynamic onMove(
    1. Move
    )?,
  7. dynamic onSetPremove(
    1. Move?
    )?,
  8. dynamic onPremove(
    1. Move
    )?,
  9. List<Move> moves = const [],
  10. required bool canMove,
  11. bool draggable = true,
  12. double dragFeedbackSize = 2.0,
  13. Offset dragFeedbackOffset = const Offset(0.0, -1.0),
  14. bool allowAnimation = true,
  15. Duration? animationDuration,
  16. Curve? animationCurve,
})

Implementation

BoardController({
  required this.pieceSet,
  required this.state,
  required this.theme,
  this.size = const BoardSize(8, 8),
  this.highlightTheme,
  this.onMove,
  this.onSetPremove,
  this.onPremove,
  this.moves = const [],
  required this.canMove,
  this.draggable = true,
  this.dragFeedbackSize = 2.0,
  this.dragFeedbackOffset = const Offset(0.0, -1.0),
  this.allowAnimation = true,
  this.animationDuration,
  this.animationCurve,
}) {
  moveMap = {};
  drops = [];
  for (Move m in moves) {
    if (m.handDrop) {
      drops.add(m);
      continue;
    }
    if (!moveMap.containsKey(m.from))
      moveMap[m.from] = [m];
    else
      moveMap[m.from]!.add(m);
    // Make pieces with no moves selectable
    bool whitePlayer = state.player == WHITE;
    for (int i = 0; i < state.board.length; i++) {
      String p = state.board[i];
      bool whitePiece = p == p.toUpperCase();
      if (p.isNotEmpty && whitePlayer == whitePiece) {
        if (!moveMap.containsKey(i)) moveMap[i] = [];
      }
    }
  }
}