New created player textfields get automatically focused

This commit is contained in:
2025-07-21 00:01:05 +02:00
parent 3090af9e5c
commit 7830d296c3
2 changed files with 13 additions and 3 deletions

View File

@@ -38,11 +38,16 @@ class CreateGameView extends StatefulWidget {
}
class _CreateGameViewState extends State<CreateGameView> {
final TextEditingController _gameTitleTextController =
TextEditingController();
/// List of text controllers for player names.
final List<TextEditingController> _playerNameTextControllers = [
TextEditingController()
];
final TextEditingController _gameTitleTextController =
TextEditingController();
/// List of focus nodes for player name text fields.
final List<FocusNode> _playerNameFocusNodes = [FocusNode()];
/// Maximum number of players allowed in the game.
final int maxPlayers = 5;
@@ -177,6 +182,7 @@ class _CreateGameViewState extends State<CreateGameView> {
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<CreateGameView> {
setState(() {
_playerNameTextControllers
.add(TextEditingController());
_playerNameFocusNodes.add(FocusNode());
});
WidgetsBinding.instance.addPostFrameCallback((_) {
_playerNameFocusNodes.last.requestFocus();
});
} else {
_showFeedbackDialog(CreateStatus.maxPlayers);

View File

@@ -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