78 lines
2.6 KiB
Dart
78 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:sudoku_app/models/sudoku_theme.dart';
|
|
|
|
class NumberPad extends StatelessWidget {
|
|
final int blockSize;
|
|
final SudokuTheme theme;
|
|
final Map<int, int> numberCounts;
|
|
final int? selectedNumber;
|
|
final Function(int) onNumberTapped;
|
|
final bool isLandscape; // 👈 [추가] 이 파라미터가 있어야 합니다
|
|
|
|
const NumberPad({
|
|
super.key,
|
|
required this.blockSize,
|
|
required this.theme,
|
|
required this.numberCounts,
|
|
required this.selectedNumber,
|
|
required this.onNumberTapped,
|
|
required this.isLandscape, // 👈 [추가] 생성자에 추가
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final int gridSize = blockSize * blockSize;
|
|
|
|
// 1. 버튼 위젯 리스트 생성
|
|
List<Widget> numberButtons = List.generate(gridSize, (index) {
|
|
int numberValue = index + 1;
|
|
String numberSymbol = theme.getSymbol(numberValue);
|
|
bool isSelected = (numberValue == selectedNumber);
|
|
bool isCompleted = (numberCounts[numberValue] ?? 0) >= gridSize;
|
|
|
|
Widget button = ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: isSelected ? Colors.blue.shade300 : null,
|
|
foregroundColor: isSelected ? Colors.white : null,
|
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 0),
|
|
textStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))
|
|
),
|
|
onPressed: isCompleted
|
|
? null
|
|
: () => onNumberTapped(numberValue),
|
|
child: Text(numberSymbol),
|
|
);
|
|
|
|
// 가로 모드(Wrap)에서는 Flexible로 감싸고,
|
|
// 세로 모드(Grid)에서는 감싸지 않음
|
|
if (isLandscape) {
|
|
// Flexible을 사용해 Wrap 내에서 버튼이 공간을 차지하도록 함
|
|
return Flexible(child: button);
|
|
} else {
|
|
return button;
|
|
}
|
|
});
|
|
|
|
// 2. 가로/세로 모드에 따라 다른 레이아웃 반환
|
|
if (isLandscape) {
|
|
// --- 가로 모드: Wrap 사용 (버튼이 가로로 흐름) ---
|
|
return Wrap(
|
|
runSpacing: 4.0, // 줄(세로) 간격
|
|
spacing: 4.0, // 버튼(가로) 간격
|
|
children: numberButtons,
|
|
);
|
|
} else {
|
|
// --- 세로 모드: GridView 사용 (블록 모양) ---
|
|
return GridView.count(
|
|
crossAxisCount: blockSize, // 2x2, 3x3, 4x4, 5x5
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
padding: EdgeInsets.zero,
|
|
mainAxisSpacing: 4,
|
|
crossAxisSpacing: 4,
|
|
children: numberButtons,
|
|
);
|
|
}
|
|
}
|
|
} |