Updated function and limited name length to 12
This commit is contained in:
@@ -73,11 +73,14 @@ class GameSession extends ChangeNotifier {
|
|||||||
(json['roundList'] as List).map((e) => Round.fromJson(e)).toList();
|
(json['roundList'] as List).map((e) => Round.fromJson(e)).toList();
|
||||||
|
|
||||||
/// Returns the length of all player names combined.
|
/// Returns the length of all player names combined.
|
||||||
int getLengthOfPlayerNames() {
|
int getMaxLengthOfPlayerNames() {
|
||||||
int length = 0;
|
int length = 0;
|
||||||
for (String player in players) {
|
for (String player in players) {
|
||||||
length += player.length;
|
if (player.length >= length) {
|
||||||
|
length = player.length;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
print('Maximale Länge der Spielernamen: $length');
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: CupertinoTextField(
|
child: CupertinoTextField(
|
||||||
controller: _playerNameTextControllers[index],
|
controller: _playerNameTextControllers[index],
|
||||||
|
maxLength: 12,
|
||||||
placeholder:
|
placeholder:
|
||||||
'${AppLocalizations.of(context).player} ${index + 1}',
|
'${AppLocalizations.of(context).player} ${index + 1}',
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ void main() {
|
|||||||
|
|
||||||
group('Helper Functions', () {
|
group('Helper Functions', () {
|
||||||
test('getLengthOfPlayerNames', () {
|
test('getLengthOfPlayerNames', () {
|
||||||
expect(session.getLengthOfPlayerNames(),
|
expect(session.getMaxLengthOfPlayerNames(), equals(7)); // Charlie(7)
|
||||||
equals(15)); // Alice(5) + Bob(3) + Charlie(7)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('increaseRound', () {
|
test('increaseRound', () {
|
||||||
|
|||||||
Reference in New Issue
Block a user