From 7830d296c32b7792cc553bf47c78dec3f7a1e746 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Mon, 21 Jul 2025 00:01:05 +0200 Subject: [PATCH] New created player textfields get automatically focused --- lib/presentation/views/create_game_view.dart | 14 ++++++++++++-- pubspec.yaml | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/presentation/views/create_game_view.dart b/lib/presentation/views/create_game_view.dart index 5f9dbf0..b81437c 100644 --- a/lib/presentation/views/create_game_view.dart +++ b/lib/presentation/views/create_game_view.dart @@ -38,11 +38,16 @@ class CreateGameView extends StatefulWidget { } class _CreateGameViewState extends State { + final TextEditingController _gameTitleTextController = + TextEditingController(); + + /// List of text controllers for player names. final List _playerNameTextControllers = [ TextEditingController() ]; - final TextEditingController _gameTitleTextController = - TextEditingController(); + + /// List of focus nodes for player name text fields. + final List _playerNameFocusNodes = [FocusNode()]; /// Maximum number of players allowed in the game. final int maxPlayers = 5; @@ -177,6 +182,7 @@ class _CreateGameViewState extends State { Expanded( child: CupertinoTextField( controller: _playerNameTextControllers[index], + focusNode: _playerNameFocusNodes[index], maxLength: 12, placeholder: '${AppLocalizations.of(context).player} ${index + 1}', @@ -245,6 +251,10 @@ class _CreateGameViewState extends State { setState(() { _playerNameTextControllers .add(TextEditingController()); + _playerNameFocusNodes.add(FocusNode()); + }); + WidgetsBinding.instance.addPostFrameCallback((_) { + _playerNameFocusNodes.last.requestFocus(); }); } else { _showFeedbackDialog(CreateStatus.maxPlayers); diff --git a/pubspec.yaml b/pubspec.yaml index 4bbcdd3..0c5c712 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.5.2+584 +version: 0.5.2+585 environment: sdk: ^3.5.4