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