diff --git a/lib/data/game_session.dart b/lib/data/game_session.dart index 4896e02..cdbb461 100644 --- a/lib/data/game_session.dart +++ b/lib/data/game_session.dart @@ -73,11 +73,14 @@ class GameSession extends ChangeNotifier { (json['roundList'] as List).map((e) => Round.fromJson(e)).toList(); /// Returns the length of all player names combined. - int getLengthOfPlayerNames() { + int getMaxLengthOfPlayerNames() { int length = 0; for (String player in players) { - length += player.length; + if (player.length >= length) { + length = player.length; + } } + print('Maximale Länge der Spielernamen: $length'); return length; } diff --git a/lib/views/create_game_view.dart b/lib/views/create_game_view.dart index 5ac5026..adcbf86 100644 --- a/lib/views/create_game_view.dart +++ b/lib/views/create_game_view.dart @@ -183,6 +183,7 @@ class _CreateGameState extends State { Expanded( child: CupertinoTextField( controller: _playerNameTextControllers[index], + maxLength: 12, placeholder: '${AppLocalizations.of(context).player} ${index + 1}', padding: const EdgeInsets.all(12), diff --git a/test/data/game_session_test.dart b/test/data/game_session_test.dart index 0e9bfa1..0ab65d0 100644 --- a/test/data/game_session_test.dart +++ b/test/data/game_session_test.dart @@ -62,8 +62,7 @@ void main() { group('Helper Functions', () { test('getLengthOfPlayerNames', () { - expect(session.getLengthOfPlayerNames(), - equals(15)); // Alice(5) + Bob(3) + Charlie(7) + expect(session.getMaxLengthOfPlayerNames(), equals(7)); // Charlie(7) }); test('increaseRound', () {