getImageToDisplay function

Widget getImageToDisplay(
  1. {required double size,
  2. required Piece? squareState}
)

Get image to display on square

Implementation

Widget getImageToDisplay({
  required double size,
  required Piece? squareState,
}) {
  Widget imageToDisplay = const SizedBox();

  if (squareState == null) {
    return imageToDisplay;
  }

  String piece = (squareState.color == chessjs.WHITE ? 'W' : 'B') +
      squareState.type.toUpperCase();

  switch (piece) {
    case "WP":
      imageToDisplay = WhitePawn(size: size);
      break;
    case "WR":
      imageToDisplay = WhiteRook(size: size);
      break;
    case "WN":
      imageToDisplay = WhiteKnight(size: size);
      break;
    case "WB":
      imageToDisplay = WhiteBishop(size: size);
      break;
    case "WQ":
      imageToDisplay = WhiteQueen(size: size);
      break;
    case "WK":
      imageToDisplay = WhiteKing(size: size);
      break;
    case "BP":
      imageToDisplay = BlackPawn(size: size);
      break;
    case "BR":
      imageToDisplay = BlackRook(size: size);
      break;
    case "BN":
      imageToDisplay = BlackKnight(size: size);
      break;
    case "BB":
      imageToDisplay = BlackBishop(size: size);
      break;
    case "BQ":
      imageToDisplay = BlackQueen(size: size);
      break;
    case "BK":
      imageToDisplay = BlackKing(size: size);
      break;
    default:
      imageToDisplay = const SizedBox();
  }

  return imageToDisplay;
}