Select Git revision
-
Benoît Harrault authoredBenoît Harrault authored
board.dart 3.36 KiB
import 'package:flutter/material.dart';
import '../provider/data.dart';
import '../utils/game_utils.dart';
class Board {
static Container buildGameBoard(Data myProvider) {
String skin = myProvider.skin;
int maxGuessesCount = myProvider.maxGuessesCount;
int wordLength = int.parse(myProvider.length);
Widget buildCellWidget(
String cellValue, String cellTip, bool hasFocus, String foundLetter) {
Color textColor = Colors.white;
Color focusBorderColor = Colors.yellow.shade700;
Color defaultBorderColor = Colors.white;
String cellImage = 'empty';
if (cellTip != '') {
cellImage = cellTip;
}
if ((foundLetter != ' ') && (cellValue == ' ')) {
cellValue = foundLetter;
cellImage = 'good';
}
Image imageWidget = Image(
image: AssetImage('assets/skins/' + skin + '_' + cellImage + '.png'),
fit: BoxFit.fill,
);
Widget cellBackground = Container(
decoration: BoxDecoration(
border: Border.all(
width: 4.0,
color: hasFocus ? focusBorderColor : defaultBorderColor,
style: BorderStyle.solid,
),
),
child: imageWidget,
);
Text textWidget = Text(
cellValue,
style: TextStyle(
color: textColor,
fontSize: 40.0,
fontWeight: FontWeight.w900,
),
textAlign: TextAlign.center,
);
return Stack(
alignment: Alignment.center,
children: <Widget>[
cellBackground,
Center(child: textWidget),
],
);
}
List<String> guesses = myProvider.guesses;
List<TableRow> tableRows = [];
for (int lineIndex = 0; lineIndex < maxGuessesCount; lineIndex++) {
String word = '';
if (lineIndex < guesses.length) {
word = guesses[lineIndex];