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; final List originalCells; final int? selectedIndex; final int? selectedNumberPad; 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]; bool isEditable = (originalCells[index] == 0); bool isSelected = (index == selectedIndex); int selectedNumAsInt = selectedNumberPad ?? -1; String selectedNumAsSymbol = (selectedNumberPad != null) ? theme.getSymbol(selectedNumberPad!) : ""; bool isHighlighted = (cellValue != 0 && selectedNumberPad != null && cellValue == selectedNumberPad); bool isIncorrect = incorrectCells.contains(index); 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( // πŸ”½ [μˆ˜μ •] 'isSelected' 쑰건 제거 (배경색 μ—†μŒ) color: isIncorrect ? Colors.red.shade100 // 1μˆœμœ„: ν‹€λ¦Ό : isHighlighted ? Colors.blue.shade200 // 2μˆœμœ„: 숫자 ν•˜μ΄λΌμ΄νŠΈ : 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( cellValue == 0 ? '' : theme.getSymbol(cellValue), style: TextStyle( fontSize: fontSize, fontWeight: FontWeight.bold, // πŸ”½ [μˆ˜μ •] 'isSelected'λ₯Ό μ΅œμš°μ„  μˆœμœ„λ‘œ μΆ”κ°€ (ν…μŠ€νŠΈ 색상 λ³€κ²½) color: isSelected ? Colors.orange.shade700 // 1μˆœμœ„: μ„ νƒλœ μ…€ : isIncorrect ? Colors.red.shade900 // 2μˆœμœ„: ν‹€λ¦° μ…€ : isEditable ? Colors.blue // 3μˆœμœ„: μˆ˜μ • κ°€λŠ₯ μ…€ : Colors.black, // κΈ°λ³Έ (원본 숫자) ), ), ), ); }, ), ); } }