import 'package:flutter/material.dart'; import 'package:sudoku_app/models/sudoku_theme.dart'; // ๐Ÿ‘ˆ ํ…Œ๋งˆ ๋ชจ๋ธ ์ž„ํฌํŠธ class SudokuBoard extends StatelessWidget { final int blockSize; final SudokuTheme theme; // ๐Ÿ‘ˆ ์ด๋ฒˆ ๊ฒŒ์ž„์˜ ํ…Œ๋งˆ final List cells; // ๐Ÿ‘ˆ List (0, 1, 10...) final List originalCells; // ๐Ÿ‘ˆ List (0, 1, 10...) final int? selectedIndex; final int? selectedNumberPad; // 10์ง„์ˆ˜ ์ˆซ์ž (1, 10...) final Set incorrectCells; final Function(int) onCellTapped; const SudokuBoard({ super.key, required this.blockSize, required this.theme, required this.cells, required this.originalCells, required this.selectedIndex, required this.selectedNumberPad, required this.incorrectCells, required this.onCellTapped, }); @override Widget build(BuildContext context) { final int gridSize = blockSize * blockSize; // ๊ทธ๋ฆฌ๋“œ ํฌ๊ธฐ์— ๋”ฐ๋ผ ํฐํŠธ ํฌ๊ธฐ ๋™์  ์กฐ์ ˆ final double fontSize = (gridSize > 9) ? (gridSize > 16 ? 12 : 16) : 24; return AspectRatio( aspectRatio: 1.0, child: GridView.builder( physics: const NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: gridSize, ), itemCount: gridSize * gridSize, itemBuilder: (context, index) { int row = index ~/ gridSize; int col = index % gridSize; int cellValue = cells[index]; // 0, 1, 10... bool isEditable = (originalCells[index] == 0); bool isSelected = (index == selectedIndex); // int == int ๋น„๊ต bool isHighlighted = (cellValue != 0 && selectedNumberPad != null && cellValue == selectedNumberPad); bool isIncorrect = incorrectCells.contains(index); // blockSize์— ๋”ฐ๋ฅธ ๋™์  ๋ณด๋” BorderSide thickBorder = const BorderSide(color: Colors.black, width: 2.0); BorderSide thinBorder = const BorderSide(color: Colors.grey, width: 0.5); return GestureDetector( onTap: () => onCellTapped(index), child: Container( alignment: Alignment.center, decoration: BoxDecoration( color: isIncorrect ? Colors.red.shade100 : isSelected ? Colors.blue.shade100 : isHighlighted ? Colors.blue.shade200 : isEditable ? Colors.white : Colors.grey.shade200, border: Border( top: (row == 0) ? thickBorder : thinBorder, left: (col == 0) ? thickBorder : thinBorder, right: (col == gridSize - 1) ? thickBorder : (col % blockSize == blockSize - 1) ? thickBorder : thinBorder, bottom: (row == gridSize - 1) ? thickBorder : (row % blockSize == blockSize - 1) ? thickBorder : thinBorder, ), ), child: Text( // 0์ด๋ฉด ๋น„์šฐ๊ณ , ์•„๋‹ˆ๋ฉด ํ…Œ๋งˆ ๊ธฐํ˜ธ("1", "A", "๐ŸŽ") ํ‘œ์‹œ cellValue == 0 ? '' : theme.getSymbol(cellValue), style: TextStyle( fontSize: fontSize, fontWeight: FontWeight.bold, color: isIncorrect ? Colors.red.shade900 : isEditable ? Colors.blue : Colors.black, ), ), ), ); }, ), ); } }