From 9cf4a6947a4c70bbaec106623678c0b943bd4458 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 29 Jun 2025 01:55:45 +0200 Subject: [PATCH 1/8] Updated function and limited name length to 12 --- lib/data/game_session.dart | 7 +++++-- lib/views/create_game_view.dart | 1 + test/data/game_session_test.dart | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) 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', () { From 3da8c886ff923a8e89c1913948c48bf7aba9c390 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 29 Jun 2025 01:56:32 +0200 Subject: [PATCH 2/8] Updated responsive design in segmented control --- devtools_options.yaml | 3 +++ lib/views/round_view.dart | 54 ++++++++++++++++++++++++++++----------- pubspec.yaml | 2 +- 3 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 devtools_options.yaml diff --git a/devtools_options.yaml b/devtools_options.yaml new file mode 100644 index 0000000..fa0b357 --- /dev/null +++ b/devtools_options.yaml @@ -0,0 +1,3 @@ +description: This file stores settings for Dart & Flutter DevTools. +documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states +extensions: diff --git a/lib/views/round_view.dart b/lib/views/round_view.dart index 056d0a1..b945ec4 100644 --- a/lib/views/round_view.dart +++ b/lib/views/round_view.dart @@ -67,6 +67,7 @@ class _RoundViewState extends State { @override Widget build(BuildContext context) { final bottomInset = MediaQuery.of(context).viewInsets.bottom; + final maxLength = widget.gameSession.getMaxLengthOfPlayerNames(); return CupertinoPageScaffold( resizeToAvoidBottomInset: false, @@ -122,15 +123,8 @@ class _RoundViewState extends State { index, Padding( padding: EdgeInsets.symmetric( - horizontal: widget.gameSession - .getLengthOfPlayerNames() > - 20 - ? (widget.gameSession - .getLengthOfPlayerNames() > - 32 - ? 5 - : 10) - : 15, + horizontal: + _getSegmendetControlPadding(maxLength), vertical: 6, ), child: Text( @@ -139,11 +133,9 @@ class _RoundViewState extends State { maxLines: 1, style: TextStyle( fontWeight: FontWeight.bold, - fontSize: widget.gameSession - .getLengthOfPlayerNames() > - 28 - ? 14 - : 18, + fontSize: _getSegmendetControlFontSize( + widget.gameSession + .getMaxLengthOfPlayerNames()), ), ), ), @@ -191,7 +183,13 @@ class _RoundViewState extends State { borderRadius: BorderRadius.circular(12), child: CupertinoListTile( backgroundColor: CupertinoColors.secondaryLabel, - title: Row(children: [Text(name)]), + title: Row(children: [ + Expanded( + child: Text( + name, + overflow: TextOverflow.ellipsis, + )) + ]), subtitle: Text( '${widget.gameSession.playerScores[index]}' ' ${AppLocalizations.of(context).points}'), @@ -395,6 +393,32 @@ class _RoundViewState extends State { } } + double _getSegmendetControlFontSize(int maxLength) { + if (maxLength > 8) { + // 9 - 12 characters + return 9.0; + } else if (maxLength > 4) { + // 5 - 8 characters + return 15.0; + } else { + // 0 - 4 characters + return 18.0; + } + } + + double _getSegmendetControlPadding(int maxLength) { + if (maxLength > 8) { + // 9 - 12 characters + return 0.0; + } else if (maxLength > 4) { + // 5 - 8 characters + return 5.0; + } else { + // 0 - 4 characters + return 8.0; + } + } + @override void dispose() { for (final controller in _scoreControllerList) { diff --git a/pubspec.yaml b/pubspec.yaml index b0bf86a..ffc7346 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: cabo_counter description: "Mobile app for the card game Cabo" publish_to: 'none' -version: 0.3.2+244 +version: 0.3.2+248 environment: sdk: ^3.5.4 From 9fcd919847cd2c1740c00be179896c8de78924a4 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 1 Jul 2025 21:29:10 +0200 Subject: [PATCH 3/8] Implemented FittedBox Widget --- lib/views/round_view.dart | 22 ++++++++++++---------- pubspec.yaml | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/views/round_view.dart b/lib/views/round_view.dart index b945ec4..b1b98e3 100644 --- a/lib/views/round_view.dart +++ b/lib/views/round_view.dart @@ -123,19 +123,21 @@ class _RoundViewState extends State { index, Padding( padding: EdgeInsets.symmetric( - horizontal: + horizontal: 4 + _getSegmendetControlPadding(maxLength), vertical: 6, ), - child: Text( - name, - textAlign: TextAlign.center, - maxLines: 1, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: _getSegmendetControlFontSize( - widget.gameSession - .getMaxLengthOfPlayerNames()), + child: FittedBox( + fit: BoxFit.scaleDown, + child: Text( + name, + textAlign: TextAlign.center, + maxLines: 1, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: _getSegmendetControlFontSize( + maxLength), + ), ), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index ffc7346..0ba04e5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: cabo_counter description: "Mobile app for the card game Cabo" publish_to: 'none' -version: 0.3.2+248 +version: 0.3.3+255 environment: sdk: ^3.5.4 @@ -26,6 +26,7 @@ dependencies: sdk: flutter intl: any syncfusion_flutter_charts: ^30.1.37 + auto_size_text: ^3.0.0 dev_dependencies: flutter_test: From 59c710a43fde69752c8b8a51ebebea3fbf6369c7 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 1 Jul 2025 22:29:23 +0200 Subject: [PATCH 4/8] Removed print --- lib/data/game_session.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/data/game_session.dart b/lib/data/game_session.dart index cdbb461..80f1152 100644 --- a/lib/data/game_session.dart +++ b/lib/data/game_session.dart @@ -80,7 +80,6 @@ class GameSession extends ChangeNotifier { length = player.length; } } - print('Maximale Länge der Spielernamen: $length'); return length; } From 3e0482e963f2005c580e49a23ddd971d939651ab Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 1 Jul 2025 22:29:31 +0200 Subject: [PATCH 5/8] Refactored method names --- lib/views/round_view.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/views/round_view.dart b/lib/views/round_view.dart index b1b98e3..c40db1b 100644 --- a/lib/views/round_view.dart +++ b/lib/views/round_view.dart @@ -124,7 +124,7 @@ class _RoundViewState extends State { Padding( padding: EdgeInsets.symmetric( horizontal: 4 + - _getSegmendetControlPadding(maxLength), + _getSegmentedControlPadding(maxLength), vertical: 6, ), child: FittedBox( @@ -135,7 +135,7 @@ class _RoundViewState extends State { maxLines: 1, style: TextStyle( fontWeight: FontWeight.bold, - fontSize: _getSegmendetControlFontSize( + fontSize: _getSegmentedControlFontSize( maxLength), ), ), @@ -395,7 +395,7 @@ class _RoundViewState extends State { } } - double _getSegmendetControlFontSize(int maxLength) { + double _getSegmentedControlFontSize(int maxLength) { if (maxLength > 8) { // 9 - 12 characters return 9.0; @@ -408,7 +408,7 @@ class _RoundViewState extends State { } } - double _getSegmendetControlPadding(int maxLength) { + double _getSegmentedControlPadding(int maxLength) { if (maxLength > 8) { // 9 - 12 characters return 0.0; From 3c09d1f7f2e238915e8d229fe734afde9a973a64 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 1 Jul 2025 22:34:42 +0200 Subject: [PATCH 6/8] Corrected tests --- test/data/game_session_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/data/game_session_test.dart b/test/data/game_session_test.dart index 0ab65d0..de4e284 100644 --- a/test/data/game_session_test.dart +++ b/test/data/game_session_test.dart @@ -61,8 +61,8 @@ void main() { }); group('Helper Functions', () { - test('getLengthOfPlayerNames', () { - expect(session.getMaxLengthOfPlayerNames(), equals(7)); // Charlie(7) + test('getMaxLengthOfPlayerNames', () { + expect(session.getMaxLengthOfPlayerNames(), equals(7)); // Charlie (7) }); test('increaseRound', () { From 9d3d6b3ca3688643408ef920596487be087a0ba6 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 1 Jul 2025 22:34:49 +0200 Subject: [PATCH 7/8] Corrected docs --- lib/data/game_session.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/data/game_session.dart b/lib/data/game_session.dart index 80f1152..a741ae8 100644 --- a/lib/data/game_session.dart +++ b/lib/data/game_session.dart @@ -72,7 +72,7 @@ class GameSession extends ChangeNotifier { roundList = (json['roundList'] as List).map((e) => Round.fromJson(e)).toList(); - /// Returns the length of all player names combined. + /// Returns the length of the longest player name. int getMaxLengthOfPlayerNames() { int length = 0; for (String player in players) { From aca46fec0f730dd4f83553c68a26fa4c3c5ace07 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 1 Jul 2025 22:35:00 +0200 Subject: [PATCH 8/8] Removed unused package --- pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index f0a8fd2..7dc76bd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,7 +26,6 @@ dependencies: sdk: flutter intl: any syncfusion_flutter_charts: ^30.1.37 - auto_size_text: ^3.0.0 dev_dependencies: flutter_test: