Select Git revision
activity.dart
-
Benoît Harrault authoredBenoît Harrault authored
keyboard.dart 1.90 KiB
import 'dart:math';
import 'package:flutter/material.dart';
import '../provider/data.dart';
import '../utils/game_utils.dart';
class Keyboard {
static Container buildWidget(Data myProvider) {
final List<List<String>> keys = [
['A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
['Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M'],
['<', ' ', 'W', 'X', 'C', 'V', 'B', 'N', ' ', '!'],
];
Widget buildKeyWidget(String key) {
String displayedText = key;
if (key == '<') {
displayedText = '⬅️';
} else if (key == '!') {
displayedText = '☑️';
}
Color keyColor = Colors.black;
return FlatButton(
child: Text(
displayedText,
style: TextStyle(
color: keyColor,
fontSize: 30.0,
fontWeight: FontWeight.w800,
),
textAlign: TextAlign.center
),
onPressed: () {
if (key == '<') {
GameUtils.removeLetter(myProvider);
} else if (key == '!') {
GameUtils.submitWord(myProvider);
} else if (key != ' ') {
GameUtils.addLetter(myProvider, key);
}
},
);
}
List<TableRow> tableRows = [];
keys.forEach((row) {
List<Column> tableCells = [];
row.forEach((key) {
tableCells.add(
Column(
children: [ buildKeyWidget(key) ]
)
);
});
tableRows.add(
TableRow(
children: tableCells
)
);
});
return Container(
margin: EdgeInsets.symmetric(horizontal: 2),
padding: EdgeInsets.all(2),
child: Table(