99 lines
3.7 KiB
Dart
99 lines
3.7 KiB
Dart
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<int> cells; // 👈 List<int> (0, 1, 10...)
|
|
final List<int> originalCells; // 👈 List<int> (0, 1, 10...)
|
|
final int? selectedIndex;
|
|
final int? selectedNumberPad; // 10진수 숫자 (1, 10...)
|
|
final Set<int> 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,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
} |