Added Keyboard type, input restriction and different action buttons
This commit is contained in:
@@ -15,7 +15,8 @@ class GameSession {
|
|||||||
[7, 1, 4, 2],
|
[7, 1, 4, 2],
|
||||||
[7, 0, 3, 4],
|
[7, 0, 3, 4],
|
||||||
[5, 5, 0, 0],
|
[5, 5, 0, 0],
|
||||||
[10, 3, 3, 2]
|
[10, 3, 3, 2],
|
||||||
|
[30, 10, 15, 5]
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
playerIndices.sort((a, b) {
|
playerIndices.sort((a, b) {
|
||||||
int scoreA = widget.gameSession.playerScores[a][0];
|
int scoreA = widget.gameSession.playerScores[a][0];
|
||||||
int scoreB = widget.gameSession.playerScores[b][0];
|
int scoreB = widget.gameSession.playerScores[b][0];
|
||||||
return scoreB.compareTo(scoreA); // Absteigende Sortierung
|
return scoreA.compareTo(scoreB); // Absteigende Sortierung
|
||||||
});
|
});
|
||||||
print('playerIndices sortiert: $playerIndices');
|
print('playerIndices sortiert: $playerIndices');
|
||||||
return playerIndices;
|
return playerIndices;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
|
padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
|
||||||
child: CupertinoTextField(
|
child: CupertinoTextField(
|
||||||
|
maxLength: 8,
|
||||||
prefix: Text('Name'),
|
prefix: Text('Name'),
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
placeholder: 'Titel des Spiels',
|
placeholder: 'Titel des Spiels',
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
final List<GameSession> gameSessionArray = [
|
final List<GameSession> gameSessionArray = [
|
||||||
GameSession(
|
GameSession(
|
||||||
gameTitle: 'Spiel am 27.02.2025',
|
gameTitle: 'Spiel am 27.02.2025',
|
||||||
players: ['Alex', 'Ben', 'Clara'],
|
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
|
||||||
winner: 'Clara',
|
winner: 'Clara',
|
||||||
gameMode: 0),
|
gameMode: 0),
|
||||||
GameSession(
|
GameSession(
|
||||||
gameTitle: 'Freundschaftsrunde',
|
gameTitle: 'Freundschaftsrunde',
|
||||||
players: ['Jonas', 'Felix', 'Nils'],
|
players: ['Felix', 'Jonas', 'Nils'],
|
||||||
winner: 'Jonas',
|
winner: 'Jonas',
|
||||||
gameMode: 1),
|
gameMode: 1),
|
||||||
GameSession(
|
GameSession(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:cabo_counter/data_classes/game_session.dart';
|
import 'package:cabo_counter/data_classes/game_session.dart';
|
||||||
import 'package:cabo_counter/utility/styles.dart';
|
import 'package:cabo_counter/utility/styles.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class RoundView extends StatefulWidget {
|
class RoundView extends StatefulWidget {
|
||||||
final GameSession gameSession;
|
final GameSession gameSession;
|
||||||
@@ -16,13 +17,21 @@ class RoundView extends StatefulWidget {
|
|||||||
class _RoundViewState extends State<RoundView> {
|
class _RoundViewState extends State<RoundView> {
|
||||||
late final List<bool> _isKamikazeChecked =
|
late final List<bool> _isKamikazeChecked =
|
||||||
List.filled(widget.gameSession.players.length, false);
|
List.filled(widget.gameSession.players.length, false);
|
||||||
late final List<TextEditingController> _pointControllers =
|
late final List<TextEditingController> _pointControllers = List.generate(
|
||||||
List.filled(widget.gameSession.players.length, TextEditingController());
|
widget.gameSession.players.length,
|
||||||
late final List<bool> _hasSaidCabo =
|
(index) => TextEditingController(),
|
||||||
List.filled(widget.gameSession.players.length, false);
|
);
|
||||||
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
print('Runde ${widget.roundNumber} geöffnet');
|
print('Runde ${widget.roundNumber} geöffnet');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,20 +49,50 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(0, 50, 0, 50),
|
padding: const EdgeInsets.fromLTRB(0, 40, 0, 50),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Runde ${widget.roundNumber}',
|
'Runde ${widget.roundNumber}',
|
||||||
style: Styles.roundTitle,
|
style: Styles.roundTitle,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 5),
|
padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
|
||||||
child: CupertinoListTile(
|
child: Text('Wer hat CABO gesagt?',
|
||||||
title: Row(
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
children: [
|
),
|
||||||
Text('Name'),
|
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(
|
trailing: Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@@ -69,7 +108,8 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListView.builder(
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: widget.gameSession.players.length,
|
itemCount: widget.gameSession.players.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
@@ -89,29 +129,37 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${widget.gameSession.playerScores[index][widget.roundNumber - 1]} Punkte',
|
'${widget.gameSession.playerScores[index][widget.roundNumber - 1]} Punkte',
|
||||||
),
|
),
|
||||||
leading: CupertinoRadio(
|
|
||||||
value: _hasSaidCabo[index],
|
|
||||||
groupValue: _hasSaidCabo,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_hasSaidCabo[index] = true;
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 100,
|
width: 100,
|
||||||
child: CupertinoTextField(
|
child: CupertinoTextField(
|
||||||
keyboardType: TextInputType.number,
|
maxLength: 3,
|
||||||
controller: _pointControllers[index],
|
focusNode: _focusNodes[index],
|
||||||
placeholder: 'Punkte',
|
//keyboardType:
|
||||||
textAlign: TextAlign.center,
|
// TextInputType.numberWithOptions(
|
||||||
onChanged: (value) {
|
// signed: false, decimal: false),
|
||||||
widget.gameSession.playerScores[index]
|
keyboardType:
|
||||||
[widget.roundNumber - 1] =
|
TextInputType.numberWithOptions(
|
||||||
int.parse(value);
|
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: 20),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 50,
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user