Added Keyboard type, input restriction and different action buttons

This commit is contained in:
Felix Kirchner
2025-03-02 18:48:01 +01:00
parent 68502fa483
commit 28daabf090
5 changed files with 95 additions and 37 deletions

View File

@@ -15,7 +15,8 @@ class GameSession {
[7, 1, 4, 2],
[7, 0, 3, 4],
[5, 5, 0, 0],
[10, 3, 3, 2]
[10, 3, 3, 2],
[30, 10, 15, 5]
];
@override

View File

@@ -109,7 +109,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
playerIndices.sort((a, b) {
int scoreA = widget.gameSession.playerScores[a][0];
int scoreB = widget.gameSession.playerScores[b][0];
return scoreB.compareTo(scoreA); // Absteigende Sortierung
return scoreA.compareTo(scoreB); // Absteigende Sortierung
});
print('playerIndices sortiert: $playerIndices');
return playerIndices;

View File

@@ -44,6 +44,7 @@ class _CreateGameState extends State<CreateGame> {
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
child: CupertinoTextField(
maxLength: 8,
prefix: Text('Name'),
textAlign: TextAlign.right,
placeholder: 'Titel des Spiels',

View File

@@ -18,12 +18,12 @@ class _MainMenuViewState extends State<MainMenuView> {
final List<GameSession> gameSessionArray = [
GameSession(
gameTitle: 'Spiel am 27.02.2025',
players: ['Alex', 'Ben', 'Clara'],
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
winner: 'Clara',
gameMode: 0),
GameSession(
gameTitle: 'Freundschaftsrunde',
players: ['Jonas', 'Felix', 'Nils'],
players: ['Felix', 'Jonas', 'Nils'],
winner: 'Jonas',
gameMode: 1),
GameSession(

View File

@@ -1,6 +1,7 @@
import 'package:cabo_counter/data_classes/game_session.dart';
import 'package:cabo_counter/utility/styles.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
class RoundView extends StatefulWidget {
final GameSession gameSession;
@@ -16,13 +17,21 @@ class RoundView extends StatefulWidget {
class _RoundViewState extends State<RoundView> {
late final List<bool> _isKamikazeChecked =
List.filled(widget.gameSession.players.length, false);
late final List<TextEditingController> _pointControllers =
List.filled(widget.gameSession.players.length, TextEditingController());
late final List<bool> _hasSaidCabo =
List.filled(widget.gameSession.players.length, false);
late final List<TextEditingController> _pointControllers = List.generate(
widget.gameSession.players.length,
(index) => TextEditingController(),
);
int _caboPlayerIndex = 0;
late GameSession gameSession = widget.gameSession;
late final List<FocusNode> _focusNodes = List.generate(
widget.gameSession.players.length,
(index) => FocusNode(),
); // Neue FocusNodes-Liste
@override
void initState() {
super.initState();
print('Runde ${widget.roundNumber} geöffnet');
}
@@ -40,20 +49,50 @@ class _RoundViewState extends State<RoundView> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 50, 0, 50),
padding: const EdgeInsets.fromLTRB(0, 40, 0, 50),
child: Text(
'Runde ${widget.roundNumber}',
style: Styles.roundTitle,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 5),
child: CupertinoListTile(
title: Row(
children: [
Text('Name'),
],
padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Text('Wer hat CABO gesagt?',
style: TextStyle(fontWeight: FontWeight.bold)),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: gameSession.players.length > 3 ? 5 : 20,
vertical: 10),
child: SizedBox(
height: 40,
child: CupertinoSegmentedControl<int>(
groupValue: _caboPlayerIndex,
children: Map<int, Widget>.fromIterable(
widget.gameSession.players.asMap().keys,
value: (index) => Padding(
padding: EdgeInsets.symmetric(
horizontal: gameSession.players.length > 3 ? 7 : 15,
),
child: Text(
widget.gameSession.players[index],
style: TextStyle(
fontSize: gameSession.players.length > 3 ? 14 : 16),
),
),
),
onValueChanged: (int value) {
setState(() {
_caboPlayerIndex = value;
});
},
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 20.0),
child: CupertinoListTile(
title: Text('Spieler:in'),
trailing: Row(
children: [
SizedBox(
@@ -69,7 +108,8 @@ class _RoundViewState extends State<RoundView> {
),
),
),
ListView.builder(
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: widget.gameSession.players.length,
itemBuilder: (BuildContext context, int index) {
@@ -89,29 +129,37 @@ class _RoundViewState extends State<RoundView> {
subtitle: Text(
'${widget.gameSession.playerScores[index][widget.roundNumber - 1]} Punkte',
),
leading: CupertinoRadio(
value: _hasSaidCabo[index],
groupValue: _hasSaidCabo,
onChanged: (value) {
setState(() {
_hasSaidCabo[index] = true;
});
}),
trailing: Row(
children: [
SizedBox(
width: 100,
child: CupertinoTextField(
keyboardType: TextInputType.number,
controller: _pointControllers[index],
placeholder: 'Punkte',
textAlign: TextAlign.center,
onChanged: (value) {
widget.gameSession.playerScores[index]
[widget.roundNumber - 1] =
int.parse(value);
},
)),
width: 100,
child: CupertinoTextField(
maxLength: 3,
focusNode: _focusNodes[index],
//keyboardType:
// TextInputType.numberWithOptions(
// signed: false, decimal: false),
keyboardType:
TextInputType.numberWithOptions(
signed: true,
decimal: false,
),
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
],
textInputAction: index ==
widget.gameSession.players.length -
1
? TextInputAction.done
: TextInputAction.next,
controller: _pointControllers[index],
placeholder: 'Punkte',
textAlign: TextAlign.center,
// 👇 Action-Typ explizit setzen
onSubmitted: (_) => _nextField(index),
),
),
SizedBox(width: 20),
SizedBox(
width: 50,
@@ -132,8 +180,16 @@ class _RoundViewState extends State<RoundView> {
],
))));
},
),
)),
],
)));
}
void _nextField(int index) {
if (index < widget.gameSession.players.length - 1) {
FocusScope.of(context).requestFocus(_focusNodes[index + 1]);
} else {
_focusNodes[index].unfocus();
}
}
}