Different scroll management in round view

This commit is contained in:
Felix Kirchner
2025-04-23 23:07:38 +02:00
parent 116cfe9a6a
commit 4fc7d98347

View File

@@ -39,12 +39,11 @@ class _RoundViewState extends State<RoundView> {
@override
void initState() {
print('Runde ${widget.roundNumber} geöffnet');
print('Neuste Runde: ${widget.gameSession.round}');
if (widget.roundNumber < widget.gameSession.round) {
print('Die Runde ${widget.roundNumber} ist kleiner als die neuste '
'Runde ${widget.gameSession.round}, somit werden '
'die bereits eingetragenen Punkte angezeigt.');
print('=== Runde ${widget.roundNumber} geöffnet ===');
if (widget.roundNumber < widget.gameSession.round ||
widget.gameSession.finished == true) {
print('Die Runde ${widget.roundNumber} wurde bereits gespielt, deshalb '
'werden die alten Punktestaende angezeigt');
// If the current round has already been played, the text fields
// are filled with the scores from this round
@@ -56,8 +55,11 @@ class _RoundViewState extends State<RoundView> {
super.initState();
}
@override
@override
Widget build(BuildContext context) {
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
return CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar(
@@ -67,62 +69,76 @@ class _RoundViewState extends State<RoundView> {
leading: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () => Navigator.pop(context, widget.gameSession),
child: Text('Abbrechen'),
child: const Text('Abbrechen'),
),
),
child: Stack(
children: [
SafeArea(
Positioned.fill(
child: SingleChildScrollView(
padding: EdgeInsets.only(bottom: 100 + bottomInset),
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 40, 0, 50),
child: Text(
'Runde ${widget.roundNumber}',
style: theme.roundTitle,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Text('Wer hat CABO gesagt?',
style: TextStyle(fontWeight: FontWeight.bold)),
const SizedBox(height: 40),
Text('Runde ${widget.roundNumber}',
style: theme.roundTitle),
const SizedBox(height: 10),
const Text(
'Wer hat CABO gesagt?',
style: TextStyle(fontWeight: FontWeight.bold),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: gameSession.players.length > 3 ? 5 : 20,
vertical: 10),
horizontal:
widget.gameSession.players.length > 3 ? 5 : 20,
vertical: 10,
),
child: SizedBox(
height: 40,
child: CupertinoSegmentedControl<int>(
unselectedColor: theme.backgroundTintColor,
selectedColor: theme.primaryColor,
groupValue: _caboPlayerIndex,
children: Map<int, Widget>.fromIterable(
widget.gameSession.players.asMap().keys,
value: (index) => Padding(
children: Map.fromEntries(widget.gameSession.players
.asMap()
.entries
.map((entry) {
final index = entry.key;
final name = entry.value;
return MapEntry(
index,
Padding(
padding: EdgeInsets.symmetric(
horizontal: gameSession.getLengthOfPlayerNames() >
horizontal: widget.gameSession
.getLengthOfPlayerNames() >
20
? (gameSession.getLengthOfPlayerNames() > 32
? (widget.gameSession
.getLengthOfPlayerNames() >
32
? 5
: 10)
: 15,
vertical: 6),
vertical: 6,
),
child: Text(
widget.gameSession.players[index],
name,
textAlign: TextAlign.center,
maxLines: 1,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize:
gameSession.getLengthOfPlayerNames() > 28
fontSize: widget.gameSession
.getLengthOfPlayerNames() >
28
? 14
: 18),
: 18,
),
),
),
onValueChanged: (int value) {
);
})),
onValueChanged: (value) {
setState(() {
_caboPlayerIndex = value;
});
@@ -131,47 +147,38 @@ class _RoundViewState extends State<RoundView> {
),
),
Padding(
padding:
EdgeInsets.symmetric(vertical: 0.0, horizontal: 20.0),
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: CupertinoListTile(
title: Text('Spieler:in'),
title: const Text('Spieler:in'),
trailing: Row(
children: [
children: const [
SizedBox(
width: 100,
child: Center(child: Text('Punkte')),
),
child: Center(child: Text('Punkte'))),
SizedBox(width: 28),
SizedBox(
width: 70,
child: Center(child: Text('Kamikaze')),
),
child: Center(child: Text('Kamikaze'))),
],
),
),
),
Expanded(
child: ListView.builder(
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: widget.gameSession.players.length,
itemBuilder: (BuildContext context, int index) {
itemBuilder: (context, index) {
final name = widget.gameSession.players[index];
return Padding(
padding: EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: ClipRRect(
borderRadius:
BorderRadius.circular(12), // Radius der Ecken
borderRadius: BorderRadius.circular(12),
child: CupertinoListTile(
backgroundColor: CupertinoColors.secondaryLabel,
title: Row(
children: [
Text(widget.gameSession.players[index]),
],
),
title: Row(children: [Text(name)]),
subtitle: Text(
'${widget.gameSession.playerScores[index][0]}'
' Punkte',
),
'${widget.gameSession.playerScores[index][0]} Punkte'),
trailing: Row(
children: [
SizedBox(
@@ -180,13 +187,12 @@ class _RoundViewState extends State<RoundView> {
maxLength: 3,
focusNode: _focusNodeList[index],
keyboardType:
TextInputType.numberWithOptions(
const TextInputType.numberWithOptions(
signed: true,
decimal: false,
),
inputFormatters: [
FilteringTextInputFormatter
.digitsOnly,
FilteringTextInputFormatter.digitsOnly,
],
textInputAction: index ==
widget.gameSession.players
@@ -201,7 +207,7 @@ class _RoundViewState extends State<RoundView> {
_focusNextTextfield(index),
),
),
SizedBox(width: 50),
const SizedBox(width: 50),
GestureDetector(
onTap: () {
setState(() {
@@ -227,64 +233,75 @@ class _RoundViewState extends State<RoundView> {
),
),
child: _kamikazePlayerIndex == index
? Icon(
? const Icon(
CupertinoIcons.exclamationmark,
size: 16,
color: CupertinoColors.white)
color: CupertinoColors.white,
)
: null,
),
),
SizedBox(width: 22),
const SizedBox(width: 22),
],
))));
),
),
),
);
},
)),
),
],
)),
),
),
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
bottom: bottomInset,
child: Container(
height: 80,
decoration: BoxDecoration(
padding: const EdgeInsets.only(bottom: 20),
color: theme.backgroundTintColor,
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
CupertinoButton(
onPressed: _areRoundInputsValid()
? () => {
_finishRound(),
Navigator.pop(context, widget.gameSession)
? () {
_finishRound();
Navigator.pop(context, widget.gameSession);
}
: null,
child: const Text('Fertig'),
),
CupertinoButton(
onPressed: _areRoundInputsValid()
? () => {
_finishRound(),
Navigator.pushReplacement(context,
? () {
_finishRound();
if (widget.gameSession.finished == true) {
Navigator.pop(context, widget.gameSession);
} else {
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (context) {
return RoundView(
builder: (context) => RoundView(
gameSession: widget.gameSession,
roundNumber:
widget.roundNumber + 1);
})),
roundNumber: widget.roundNumber + 1,
),
),
);
}
}
: null,
child: const Text('Nächste Runde')),
child: const Text('Nächste Runde'),
),
],
)),
),
),
),
],
));
),
);
}
/// Focuses the next text field in the list of text fields.
@@ -332,13 +349,19 @@ class _RoundViewState extends State<RoundView> {
print('Alte Punktestaende:');
print(gameSession.printRoundScores(widget.roundNumber));
}
if (widget.roundNumber >= widget.gameSession.playerScores[0].length) {
_calculateScoredPoints();
widget.gameSession.sumPoints();
if (widget.gameSession.finished == true) {
print('Das Spiel ist beendet');
} else {
if (widget.roundNumber >= widget.gameSession.playerScores[0].length - 1) {
gameSession.expandPlayerScoreLists();
print('Das Punkte-Array wurde erweitert');
}
_calculateScoredPoints();
widget.gameSession.sumPoints();
widget.gameSession.increaseRound();
}
print('Die Punktesummen wurden aktualisiert');
}