getImageToDisplay function Null safety

Widget getImageToDisplay(
  1. {required double size,
  2. required ChessboardController controller,
  3. required dynamic squareName}
)

Get image to display on square

Implementation

Widget getImageToDisplay(
    {required double size,
    required ChessboardController controller,
    required squareName}) {
  Widget imageToDisplay = const SizedBox();

  if (controller.gameLogic.get(squareName) == null) {
    const SizedBox();
  }

  String piece = (controller.gameLogic.get(squareName)!.color == chessjs.WHITE
          ? 'W'
          : 'B') +
      controller.gameLogic.get(squareName)!.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;
}